What is wrong with my else statement?


#1

// Check if the user is ready to play!
confirm(“I understand confirm”);
var age = prompt(“whats your age?”);
if(“age is less than 13”);
{
// do this code
}
else ;console.log) ;// “have fun!”
{
// do this code
}


#2

There’s no else-statement, else is an optional part of an if-statement.
Don’t sprinkle semi-colons around. They go in particular places, and you’d put them there.
Or don’t use semi-colons unless absolutely necessary and let them be automatically inserted.
Similar to all other code, don’t guess, find out. Looking up what an if-statement looks like lets you easily compare to what you’ve done.
If you guess what something should be, then you’ve stopped describing what it should be, and nobody is in control any more. Arguably each guess you make is a bug, regardless of whether it does what you want.

google: mdn if statement


#3

Hi Zombie,
There’s a lot of info on Mozilla mdn,

That can always help you,

As for your specific problem you have semi columns where you don’t need them.

// Check if the user is ready to play!

confirm(“I understand confirm”);
var age = prompt(“whats your age?”);
if("age is less than 13") {
// do this code
} else {
console.log) ;
}

#4

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