我无法使用此代码。它一直说输入的意外结束,我无法弄清楚如何解决它。请帮忙。我的代码我看起来类似于codecademys岩石剪刀js代码的代码,因为它是相同的代码我试图自定义和修改但我不能让它工作
var myFunction = function () {
var userChoice = prompt("Do you choose rock, paper or scissors?");
var computerChoice = Math.random();
if (computerChoice < 0.34) {
computerChoice = "rock";
} else if (computerChoice <= 0.67) {
computerChoice = "paper";
} else {
computerChoice = "scissors";
}
console.log("Computer: " + computerChoice);
var compare = function (userChoice, computerChoice) {
if (userChoice === computerChoice) {
console.log("The result is a tie!")
} else if (userChoice === "rock") {
if (computerChoice === scissors) {
console.log("rock wins")
} else {
console.log("paper wins")
}
} else if (userChoice === "paper") {
if (computerChoice === "rock") {
console.log("paper wins")
} else {
console.log("scissors wins")
}
}
}
答案 0 :(得分:1)
您在代码末尾缺少}
。