Oops, try again. Did you add an if statement to your code?


#1


Exercise 5: The story heats up!


Oops, try again. Did you add an if statement to your code?


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

I keep getting this message. What is wrong with my code?


#2

Currently you have if (userAnswer = "yes") Keep in mind that a single = is used to set the value of a variable. Where as == and === are used to compare if two things are equal. The if statement should be looking to see if userAnswer is equal to "yes".


#3

// 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!");
}
else{
console.log("Oh no! Bieber shakes his head and sings 'I set a pace, so I can race without pacing.'");
}

\Whats the error in this ??


#4

This is my current code:

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

And I'm still getting the very same error. :frowning:


#5

Is this your entire code?


#6

i have a problem with the justin beiber part of the code.i use the following code:
var userAnswer = "no"

if(userAnswer == "no"){
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.'")
}
the issue with this code is that if i declare a variable userAnswer === "yes" the code runs normally when i type in the prompt box yes but if i type no in the same prompt box i didnt get the expected result which is else statement code in curly brackets.then i changed variable userAnswer === "no" but there was no difference in code.What im trying to say is what is a convenient for getting different responses eg getting else or if statement code when typing any other variable value apart from the one assigned to it.plz help


#7

With an if/else statement, if the condition is met, so I'm this case userAnswer equals whatever we set it to, the code should run. Otherwise for any other answer the else statement should run.


#8

Try something like this

var string = "You are at a Justin Bieber concert, and you hear this lyric 'Lace my shoes off, start racing.'"
console.log(string)
console.log("Suddenly, Bieber stops and says, 'Who wants to race me?'")
var userAnswer = confirm("Do you want to race Bieber on stage?")
if (userAnswer === true){
userAnswer = "yes"
}
else{
userAnswer = "no"
}
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.'")
}


#9

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