It asks if I have an if statement, when I do


#1

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 ("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

I don't understand why it gives me an error, I don't notice anything wrong.


#3

@theflashspot2_0 You did not properly set a condition in your if statement. It should be like this:

if (userAnswer = "yes")

Also, as a best practice, you should put semicolons at the end of your print to console commands.


#4

@dreamthink Thanks for the advice, however, it still gives me the same error
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, I put three equal signs because the print didn't work right without them


#5

@theflashspot2_0 Hmm... it looks ok, though I only used one equals sign when setting my condition. Sometimes it can be very finicky about the string in the console.log. Did you copy and paste the string from the instructions to make sure there are no differences with spacing between text? Try adding a semicolon after your last right curly bracket }


#6

@dreamthink Yes, I had copied and pasted them, I'll try the semicolon and see if it works.


#7

I'm getting the same thing... It says specifically, "Remember: = is for assignment, and === is to check if things are equal!"
my code:
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.'");
}


#8

This code appears to be the correct one, it is working in the interpreter correctly, but there might be a bug with codecademy that isn't passing it... Hmm a conundrum


#9

If you just add another if statement it asks if you have added and else statement. try it

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 ("Smart man!");
}

else { 
    console.log ("Oh no! Bieber shakes his head and sings 'I set a pace, so I can race without pacing.'");
}

#10

I had the same problem.
I tricked it into passing me by putting

if( true )
{
}else{
}

after the correct if/else statements.

Then in the next part "6.Asking for Feedback" I just remove the extra if/else used to trick the page to accept the answer.


#11

Yeah, seems like i have done stuff like that in previous classes to get it to pass, but it doesnt't currently seem to work.


#12

As soon as I add last and empty else { }, it says there is a problem with the syntax