gpt4 book ai didi

石头剪刀布游戏的 JavaScript 错误消息

转载 作者:行者123 更新时间:2023-12-03 10:05:10 26 4
gpt4 key购买 nike

请我需要以下代码的帮助。我收到此错误消息SyntaxError:预期表达式,获得关键字“if”,我认为我正在做正确的事情。

var userChoice = prompt("Do you choose rock, paper or scissors?");
var computerChoice = Math.random();
`enter code here`
if (computerChoice < 0.34) {
computerChoice = "rock";
} else if (computerChoice <= 0.67) {
computerChoice = "paper";
} else {
computerChoice = "scissors";
}
console.log("Computer: " + computerChoice);
var compare = function(choice1, choice2)
if (choice1 === choice2) {
return "The result is a tie!";
}

最佳答案

Javascript 中函数的内容放在大括号内。所以你当前的代码

var compare = function(choice1, choice2)
if (choice1 === choice2) {
return "The result is a tie!";
}

将成为

var compare = function(choice1, choice2)
{
if (choice1 === choice2) {
return "The result is a tie!";
}
}

关于石头剪刀布游戏的 JavaScript 错误消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30391654/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com