Please help me, I’m new in programming
The webpage is asking for the user’s age. The input value has already been fetched, but you have to fill in the missing code. When the page calls the function checkAge(), first print in the console “The input age: [age]”, followed by one of the following, depending on the value:
18 years or more: “The user is an adult.”
Under 18 years, but over 0 years: “The user is not yet an adult.”
Otherwise: “Invalid input!”
Example output:
Input age: 18
The user is an adult.
The output of the program must be exactly the same as the example output (the most strict comparison level)
My code:
function checkAge() {
var age = document.getElementById("age").value;
var age = Number(age);
if (age >= 18) {
console.log("The user is an adult.");
} else if (age > 0 && age < 18) {
console.log("The user is not yet an adult.");
} else {
console.log("Invalid input.");
}
}
Compiler gives: Incorrect output: your program printed “The”, but should have printed “Input”