我正在学习javascript,我一直有这个错误!
这是我的剧本:
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";
}
答案 0 :(得分:0)
应该是:
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";
}
或者更整洁:
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"
}
}