2. Old Enough to Play?


#1

Error: Oops, try again. There was a problem with your syntax.

Code:

confirm("I am ready to play!");
var age = prompt("what's your age?");
if (13=>) {
    console.log("You can play :)!");
} 
else 
{
    console.log("you can't play :(!");
}

#2

you have to compare the variable you created "age" to the age (13) in the if else statement:

confirm("I am ready to play!");
var age = prompt("what's your age?");
if (age >= 13) {
console.log("You can play :)!");
}
else
{
console.log("you can't play :(!");
}


#3

Also, I would rather use confirm statement instead of console.log so you can see nicely that your're good to go, or not. Something like this maybe:

confirm ("I am ready to play!");
var age = prompt("what's your age?");
if (age >= 13) {
confirm("You're ready to play");
}
else
{
confirm("you can't play :(!");
}


#4

ok i see thank you the code works now still trying to get things right :slight_smile:


#5

You can also add this to exit the script if you want user not to play if he's not old enough:

confirm ("I am ready to play!");
var age = prompt("what's your age?");
if (age >= 13) {
confirm("You're ready to play");
}
else {
throw new Error("Sorry, you're too young to play !!!");
}


#6

confirm("I am ready to play");
var age = prompt("what's your age");

if (age < 68) {
    console.log("u r 2 young");
}
else {
    console.log("walecum");
}

WHat did i do wrong fam ?!?!?!


#7

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