我的if/else语句中的'else'永远不会发生 - 有人可以解释为什么吗?

-5 javascript

只是执行codecademy课程,当我运行代码时,一切都有效,除了这个if/else语句.当它到达那个时,无论我为userAnswer提示输入什么,我只是得到'if'输出.有人可以解释原因吗?一直在读这个东西100x,答案不是跳出来的.万分感谢.

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

}
Run Code Online (Sandbox Code Playgroud)

Jos*_*ess 5

你正在设置userAnswer而不是阅读它的状态.

将条件更改为

userAnswer === "yes"
Run Code Online (Sandbox Code Playgroud)