gpt4 book ai didi

javascript - Codecademy javascript 第 7/9 课错误

转载 作者:行者123 更新时间:2023-11-28 19:00:05 25 4
gpt4 key购买 nike

我已经在 7/9 被困了 2 个晚上了。这是一个石头剪刀布的游戏。我不知道出了什么问题。我尝试了在线 lint,它还说我的第 22 行是一个错误(需要一个标识符,但看到的是“else”)。按照说明,我在比较函数内的现有代码下编写了另一个 else if 。

我的代码:

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(choice1, choice2){
if(choice1 === choice2) {
return("The result is a tie!");
}
else if(choice1 ==="rock"){
if(choice2 ==="scissors")
return("rock wins");
}
else{
return"paper wins";
}
else if(choice1 ==="paper");{
if(choice2 ==="rock")
return("paper wins");
}
else{
return"scissors wins";
}
}

最佳答案

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(choice1, choice2){
if(choice1 === choice2) {
return("The result is a tie!");
}
else if(choice1 ==="rock"){
if(choice2 ==="scissors")
return("rock wins");
}
else{
return"paper wins";
}
else if(choice1 ==="paper");{ -- on this there is semicolon after elseif block.. and how come else if is there after else block..
if(choice2 ==="rock")
return("paper wins");
}
else{
return"scissors wins";
}
}

关于javascript - Codecademy javascript 第 7/9 课错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32754026/

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