Skip to content

Instantly share code, notes, and snippets.

@geraldotech
Created December 18, 2022 16:15
Show Gist options
  • Save geraldotech/8fbd9798d7ebf031e025b9e36eef7d83 to your computer and use it in GitHub Desktop.
Save geraldotech/8fbd9798d7ebf031e025b9e36eef7d83 to your computer and use it in GitHub Desktop.
Check Age template literal
<!DOCTYPE html>
<html lang="en" style="color-scheme: dark">
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Chek Age Number</title>
</head>
<body>
<input type="number" />
<p></p>
<script>
document.querySelector("input").addEventListener("input", check);
const p = document.querySelector("p");
function check(e) {
const age = e.target.value;
p.innerHTML = `${age >= 18 ? "maior idade" : "menor idade"}`;
if (age.length == 0) {
p.innerHTML = "";
}
}
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment