JavaScript Error. 5. The story heats up


#1

// Check if the user is ready to 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 Bieber on stage?");
if (userAnswer==="yes")
{
console.log("You and Bieber start racing. It's neck and neck! You win by a shoelace!");
}
if (userAnswer==="no")
{
console.log("Oh no! Bieber shakes his head and sings 'I set a pace, so I can race without pacing.'");
}


JavaScript Error. 5. The story hearts up
#2

You shouldn't have two if statements
please add your else statement ..

This is the syntax for if/else statements:

if(condition){
  //something
}
else{
//something different
}

If the condition in the if statement is not met then it would run the else statement..
The above code is not the complete code for the lesson so please paste in the complete code if you still get the error


#3

Please help out
Here is my code but it keeps telling me "Oops, try again. Did you add an if statement to your code?

var userAnswer
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.'")}


#4

review your if-else statement. should be like this:

if (condition) {
    // block of code to be executed if the condition is true
} else { 
    // block of code to be executed if the condition is false
}

#5

still giving the giving me this 'Oops, try again. Did you add an if statement to your code? "
var userAnswer
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.'")
}


#6

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.'")
}

Also make sure that logs values are the same as instruction says.


#7

sure they are, have to copy from the instruction being given so as not to encounter typo, but still having same issue.
What do I do?


#8

Please, post link to this lesson.


#9

https://www.codecademy.com/courses/javascript-beginner-en-x9DnD/0/5?curriculum_id=506324b3a7dffd00020bf661


#10

Try to reset code and refresh browser. Try my code for this lesson:

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

var age = prompt("What's your age?");
if (age < 13){
    console.log("You are allowed to play but you take no responsibility!");
} else{
   console.log("You can 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 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.'");
}

#11

Am impressed, thank you very very much.................................. You have no idea how excited I am right now. :slight_smile:


#12