我正在尝试为代码学院制作一个石头剪刀游戏,我被告知要为compare()创建一个函数。我写了以下代码:
function compare(choice1,choice2){
if (choice1 == choice2){
console.log("The result is a tie!");
} else{
console.log("the computer wins");
}
当我跑步时,“结果是平局!”出现两次,但我得到一个错误代码说“哎呀,再试一次!你的比较功能不会返回'结果是平局!'什么时候打平。“我知道我的语法有问题,但我很新,所以我不知道在哪里。有什么帮助吗?
答案 0 :(得分:0)
你没有从函数返回,你正在记录结果。在console.log
个语句之后,请发送回return
console.log("The result is a tie!");
return true; //or whatever