gpt4 book ai didi

javascript - Codecademy 语法错误 意外标记 else

转载 作者:行者123 更新时间:2023-11-28 10:54:24 25 4
gpt4 key购买 nike

所以我正在学习 JS codecademy 类(class),我正在学习石头剪刀布的事情,我也看过其他主题,但据我所知,我没有放错分号。你能告诉我出了什么问题吗?

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 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";
} // this was missing
}else if(choice1 === "paper"){
if(choice2 === "rock"){
return "paper wins";
}else{
return "scissors wins";
}
}
}

关于javascript - Codecademy 语法错误 意外标记 else,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26895761/

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