Javascript 比较函数语法错误
我正在尝试为CodeAcademy制作一个石头剪刀游戏,有人告诉我为compare()创建一个函数。我编写了以下代码:Javascript 比较函数语法错误,javascript,syntax,Javascript,Syntax,我正在尝试为CodeAcademy制作一个石头剪刀游戏,有人告诉我为compare()创建一个函数。我编写了以下代码: function compare(choice1,choice2){ if (choice1 == choice2){ console.log("The result is a tie!"); } else{ console.log("the computer wins"); } 当我运行它时,“result is a tie!”出现两次,但我得到一个错误代码
function compare(choice1,choice2){
if (choice1 == choice2){
console.log("The result is a tie!");
} else{
console.log("the computer wins");
}
当我运行它时,“result is a tie!”出现两次,但我得到一个错误代码,上面说“Oops,再试一次!当出现tie时,你的比较函数不会返回“result is a tie!”。我知道我的语法有问题,但我是个新手,所以我不知道在哪里。有什么帮助吗?您不是从函数返回,而是记录结果。在任一
console.log
语句之后,发回一个return
console.log("The result is a tie!");
return true; //or whatever
你实际上并没有返回任何东西。我最后做了一个返回“结果是平局!”并且成功了。谢谢