var userChoice = prompt("Do you choose rock, paper or scissors");
var computerChoice = Math.random();
if (computerChoice <= .33) {
computerChoice === "rock";
}
else if (computerChoice <=.66){
computerChoice === "paper";
}
else (computerChoice <= 1) {
computerChoice === "scissors";
};
console.log(computerChoice);
接收
语法错误:意外令牌'{'。解析错误
最佳答案
您不应为else
设置条件。
else (computerChoice <= 1) {
computerChoice === "scissors";
};
应该
else {
computerChoice === "scissors";
};
或者,如果需要该条件,请使用
else if
代替else
。else if (computerChoice <= 1){
computerChoice === "scissors";
};
记住,要将值分配给变量,只需一个
=
就足够了。 ===
和==
用于比较。因此,也用
===
替换=
。