No matter what I say, it always does the if, not else


#1

// 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 I take no responsibility.");
    
}

else {
    
    console.log("Good luck, play on!");
    
}

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

It always does the "You and Bieber start racing. It's neck and neck! You win by a shoelace!" even if the user input is no. :frowning:


#2

In JavaScript, a = b means that a is b (it's an assignment).
a == b asks if a is equal to b (it's a value comparison).
a === b also asks if a is equal to b (it's a value and type comparison).

Take a look at this, it might help.


#3

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