您好我有這樣的代碼,現在語法錯誤,非法return語句
var compare = function (choice1, choice2)
{
if (choice1 === choice2)
{
return "The result is a tie!";
}
};
if (choice1 === "Rock")
{
if (choice2 === "Scissors")
{
return "Rock wins!";
}
else (choice2 = "Paper")
{
return "Paper wins!";
}
}
,但我不斷收到一個錯誤Synatax,非法return語句。
我不明白爲什麼我得到這個錯誤,我做錯了什麼?我相信語法是完全正確的。
我正在使用在線編輯器,而不是實際的IDE。
'選擇2 = 「紙」'看起來像一個錯字 – Bathsheba
也許你想要的'else if(choice2 ==「Paper」)'? - 並將if包含在'compare'函數中:) –
對你的同學作弊:http://stackoverflow.com/q/20622970/1636522:D – leaf