Javascript to check age

// Check if the user is ready to play!
confirm("Are you ready to play?");
var age = prompt("What's your age?");
if(age < 18) 
{
 console.log("You may play but we take no responsibility!");
}
else 
{
 console.log("Let's get ready to play!");
}

Error: It looks like you didn't check for the user's age.

Note: The above code should check the user’s age.

Your code is working you can check the user age http://jsfiddle.net/wt4q2oat/2/

Do you have an actual question regarding that JavaScript code?

confirm and prompt are old fashioned debugging calls that should no longer be used as they were replaced by the debugger and console.log calls some time ago.

Your code doesn’t actually contain anything except debugging statements.

Yes, actually the code does what is said there. If I enter a number less than 18, it gives me the first comment and if I enter a number greater than 18, it displays the second comment. However, I still get the error I mentioned above after the code executes, so I was wondering why that’s the case. Thanks for your reply though.

Hi, thanks for your response. Sorry, I am just a beginner in Javascript and learning some coding at codeacademy.com. This is the code and error I got there when I was doing some examples. I had no idea that those were old commands.

Codecademy often rejects valid code since it expects you to answer a certain way. If you are certain you get hte correct answer, I’d just skip it and go on. You know you got it right.

Great! Thanks for that clarification :smile:

From the codeacademy choose your own adventure exercise, it seems that you’re needing to check the age is 13 instead of 18.
Get that particular detail right and you’ll be able to carry on.

Oh ok. I guess I didn’t notice the age correctly. Thanks for the help, Paul! Greatly appreciate it! :slight_smile:

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