Error on 2/7 Old enough to play?


What have I done wrong:

I click on Save and Submit code and it displays - Play on!

But then it gives me the following error:

Error: Did you set the age variable equal to the result of prompting the user?

I did notice that there was no option to enter a value for the users age but there are no instructions on how to do this!!


// Check if the user is ready to play!
confirm ("Ready to play?");

// prompt user for their age
var age = prompt("What's your age");

if (age < 13)
//do this
console.log("Play at your own risk.");

else //otherwise
//do this
console.log("Play on!");


Refresh your browser tab.
I don't see any problems in your code.


You need to set your variable age with this code:

var age = ("25");


That isn't what the exercise has in mind. It would like you to set your variable age by asking the user for their age, like this:

var age = prompt("What's your age");

Do you see how that works?


I'm getting a syntax error for the exercise, can anyone see where I'm going wrong?

// Check if the user is ready to play!
confirm ("Are you ready to play");
var age = prompt ("What is your age");
if (age < 13);
    console.log ("You may play this game but we take no responsbility");
    console.log ("Have a great time!");


Putting a semicolon after the condition like that is a syntax error.

Semicolons are used to end statements. If you are really going to end your if statement right there then you don't need an if statement at all because it has done nothing for you so far. It is only in the next few lines that it is doing work for you.


Thanks AB that worked.