A little help, please... Age Verification



I can not figure out what I'm doing wrong... I keep getting this error message: Oops, try again. It looks like you didn't check for the user's age.
Thanks in advance for any help received!

// Check if the user is ready to play!
confirm ("Ready to play?");
var age = (21);
var age = prompt("What's your age?");
if (age < 21) {
    // Check age of user and produce proper output
console.log ("Come back in a few birthdays, Youngin'!");
else  {
console.log ("Prepare for battle, Lunch Meat!");


Quote from instructions:

Then write an if / else statement. If age is less than 13, use console.log to tell the user that they're allowed to play but you take no responsibility.

So you have to change the condition of if to age < 13.

Extra note, this line:

var age = (21);

is not needed. In the next line, you assign to age value inputted by the user.


It worked! Thanks. So I was having trouble because my "var age" and "if age" were set as the same?


You're very welcome :slight_smile:

No, not really. Let me summarize my previous post in two points:

  1. Line var age = (21); does not affect the result of your code. This line is simply insignificant because you change the value of this variable in the next line. So if user types 14 then the value of age is 14, not 21. This line does not affect the result of your code and it does not affect the tests that codecademy executes to check if your code is correct.
  2. Your code checks whether the user is younger than 21 years old or not. But according to instructions you should check if age < 13. And that was the problem. Condition of your if construction was different than expected.


this works thanks guys this has helped me in my robotics class.


Cool... Thanks again.


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.