简体   繁体   English

岩石,纸张,剪刀游戏的Javascript错误消息

[英]Javascript error message for rock, paper, scissors game

Please i need help with the code below. 请我需要以下代码的帮助。 I have been getting this error message SyntaxError: expected expression, got keyword 'if' and I think I'm doing the right thing. 我一直在收到此错误消息SyntaxError:期望的表达式,得到了关键字'if' ,我认为我在做正确的事情。

 var userChoice = prompt("Do you choose rock, paper or scissors?"); var computerChoice = Math.random(); `enter code here` if (computerChoice < 0.34) { computerChoice = "rock"; } else if (computerChoice <= 0.67) { computerChoice = "paper"; } else { computerChoice = "scissors"; } console.log("Computer: " + computerChoice); var compare = function(choice1, choice2) if (choice1 === choice2) { return "The result is a tie!"; } 

Content of functions in Javascript goes inside braces. Javascript函数的内容放在花括号中。 So your current code 所以你当前的代码

var compare = function(choice1, choice2)
if (choice1 === choice2) {
  return "The result is a tie!";
}

will become 会变成

var compare = function(choice1, choice2)
{
    if (choice1 === choice2) {
      return "The result is a tie!";
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM