Need help asap with javascript if/else statements


#1

so i've typed

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 keep getting the same error response " Oops, try again. Your code doesn't look quite right. Check the Hint if you need help! "

There are other times where i've typed

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 it'll say " Oops, try again. Did you add an if statement to your code? "

If anyone can help me out with my problem. It would be highly appreciated! (:


#2

if (userAnswer = "yes") {

Remember, If statements use comparative operators, right now you're using an assignment operator.

In short, just add another equals sign behind the first one on this line. After that you should be good to go!


#3

@lolman is correct. You also need to remember to put a semicolon at the end of each line of code, like so:

console.log("Hello world"); //semicolon

Instead of

console.log("Hello world")//no semicolon