Syntax error :(((


#1

What am I doing wrong now?

// Check if the user is ready to play!
prompt("Are you ready to play?");
var age = prompt("What's your age");
if(age < 13 || false) {
console.log("You take full responsibility for playing this game");
}
else {
console.log("Let's play!");
}
console.log("You are at a Justin Bieber concert, and you hear this lyric 'Lace my shoes off, start racing.'");
console.log("Suddenly, Bieber stops and says, 'Who wants to race me?'");
var userAnswer = prompt("Do you want to race Bibier on stage?");
if(userAnswer === "yes"); {
console.log("You and Bieber start racing. It's neck and neck! You win by a shoelace!");
}
else {
console.log("Oh no! Bieber shakes his head and sings 'I set a pace, so I can race without pacing.'");
}


#2

You might want to run the code in a different interpreter that has more verbose error messages.

For example, nodejs says:

/media/sf_Code/coreace.js:16
else {
^^^^
SyntaxError: Unexpected token else
    at Module._compile (module.js:439:25)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Function.Module.runMain (module.js:497:10)
    at startup (node.js:119:16)
    at node.js:935:3

#3

Thank you @ionatan,

the console says "SyntaxError: Unexpected token else". I get is the 'else' fault (well mine really) but I don't get why?


#4

You've got a line number from my error message so you know which else it is.

And you know when else is expected, because it always follows what?


#5

I think the issue lies in:

Here's my edit. Try this:

// Check if the user is ready to play!
confirm("I am ready to play!");

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

if (age < 13)
{
    console.log("You're allowed to play but you take no responsibility!");
}
else 
{
    console.log("Play on!");
}

console.log("You are at a Justin Bieber concert, and you hear this lyric 'Lace my shoes off, start racing.'");

console.log("Suddenly, Bieber stops and says, 'Who wants to race me?'");

var userAnswer = prompt("Do you want to race Bieber on stage?");

console.log("Do you want to race Bieber on stage?");

if (userAnswer === "Yes")
{
    console.log("You and Bieber start racing. It's neck and neck! You win by a shoelace!");
}
else 
{
    console.log("Oh no! Bieber shakes his head and sings 'I set a pace, so I can race without pacing.'");
}

#6

Thank you both @ionatan and @bayoishola20 I have fixed it now

it was the semicolon.. Funnily enough if(age < 13 || false) didn't bother it..


#7

Yes. An if-statement has a condition and after that follows a single statement that is executed if the condition evaluated to true
Multiple statements can be grouped into a single statement with curly braces.
You ended that statement by putting a semi-colon after the condition.