Could someone help me with this code?


#1


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

if(age>13)
{
    console.log("Enjoy the game");
}
else
{
    console.log("you are allowed to play but we take no responsiblity");
}

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?");

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.'");
}
var feedback=prompt("Please give a rating.");
if(feedback>8){
    console.log("Thank you! We should race at the next concert!");
}else{
    console.log("I'll keep practicing coding and racing.");
}


#2

could you include a link to the exercise and your error message?


#3

Ok so assuming you are on 2.) Code Your Own Adventure 6.) Asking for Feedback and assuming that indeed your error is unexpected token else then I think I can help you out.

Your problem is your else statement in the above quoted lines. Play around with it to try and fix the issue.


#4

if(userAnswer==="yes"); <--------------------------------- Here!
{
    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.'");
}

@kyleaw and @bibleman13, you guys need to pay more attention! :laughing:

(It's the semicolon btw, remove this and it'll work :wink: )


#5

Yeah, my problem is my code had semi colons throughout and mine is fine so I am susceptible to those stray grammatical marks of evil...


#6

I rarely have that problem, because I use

if (blah) {
    //blah blah
}
else {
    //blah
}

instead of

if (blah)
{
    //blah blah
}
else
{
//blah
}

Looks much better too, imo. :slight_smile:


#7

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