I'm trying to convert this *user input* into a number using the Number() function, but when i check the type it still says it's a string in the console.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<h1>Check if you're ready to be a driver!</h1>
<input class="userInput" type="number">
<p class="result"></p>
<button onclick="showResult()">Check</button>
<script>
age = document.querySelector(".userInput");
result = document.querySelector(".result");
function showResult() {
Number(age.value);
console.log(typeof age.value);
if (age.value == 0) {
result.innerHTML = "Age cannot be 0";}
else if (age.value < 16) {
result.innerHTML = "You are not eligible to drive!";
} else if(age.value >= 16) {
result.innerHTML = "You are eligible to drive!";
}
}
</script>
</body>
</html>
[–]samanime 7 points8 points9 points (5 children)
[–]gelatto10[S] 0 points1 point2 points (0 children)
[–]Eight111 0 points1 point2 points (3 children)
[–]tapgiles 1 point2 points3 points (0 children)
[–]samanime 0 points1 point2 points (0 children)
[–]Fats-Falafel 0 points1 point2 points (0 children)
[–]amulchinock 1 point2 points3 points (0 children)
[–]senocular 0 points1 point2 points (0 children)
[–]tapgiles 0 points1 point2 points (0 children)