所以我正在进行JS代码课程,而且我在摇滚剪刀上做了一件事,而且我已经看过其他主题了,但是我没有错误的分号。我知道。你能告诉我出了什么问题吗?
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";
}
}
}
}
答案 0 :(得分:1)
看起来你搞砸了大括号:
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";
}
}
}
答案 1 :(得分:-2)
如果出现以下情况,则其他人会跟着其他人:
else{
return "paper wins";
}else if(choice1 === "paper"){
if(choice2 === "rock"){
return "paper wins";
}