2015-05-22 46 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!"; 
    } 
}