2016-04-24 35 views
0

我是新來的,開始嘗試使用Code Academy學習代碼。到目前爲止,我一直做得很好,掌握了一些東西。不過,我打他們的「石頭,剪子,布」的功能任務有點牆,在第6步「意外的輸入結束」 - 代碼學院搖滾紙剪刀

這裏是我的代碼:

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

else if (choice1 === "rock") { 

if (choice2 ==="scissors") { 
    return "Rock wins"; 
} 
else { 
    return "Paper wins"; 
} 
} 

出於某種原因,我不斷收到「意外結束輸入「錯誤,儘管我完全按照練習中的說法進行了練習。它沒有指出錯誤的確切位置,所以我有點失落。

回答

2

你錯過截止}您的函數聲明:

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

    else if (choice1 === "rock") { 

    if (choice2 === "scissors") { 
     return "Rock wins"; 
    } 
    else { 
     return "Paper wins"; 
    } 
    } 
} // <--- Closing '}' for function