2015-05-22 57 views
0

请帮我下面的代码。 我已经收到此错误消息语法错误:预期的表现,“如果”了关键字,我觉得我做了正确的事情。在Javascript功能岩石,纸张,剪刀游戏的Javascript错误消息

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!"; 
 
}

回答

1

内容去括号括起来的。所以,当前的代码

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

将成为

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