這是一個問題:Switch語句的javaScript
After your prompt, add a switch statement that will test for several different cases (that is, different possible user inputs). Create as many as you like! (Do at least three.) Don't forget to include a default block at the end that will provide a response if the user's choice doesn't match one of your cases.
這是我的代碼:
var user = prompt ("Can you compelete the task?").toLowerCase();
switch (the ninja stopped you from moving forward) {
case 'fight':
console.log("Are you strong enough" && "smart enough");
break;
case 'run':
console.log("Are you fast enough outrun the ninja");
break;
case 'pay':
console.log("Can you afford to pay the ninja");
break;
default:
console.log("or will you be defeated by the ninja");
};
這是我得到我去了的代碼,但找不到錯誤對不起錯誤提前我是一個非常新的程序員感謝提前的幫助。
語法錯誤:缺少)開關後表達
你期望什麼「'忍者阻止你前進''做什麼?這不是有效的語法,這就是爲什麼你得到你的語法錯誤。 –
在你的switch語句中,這些詞應該是什麼意思?這只是一句話;它應該是一個表達。 – Pointy
這是[MDN的JavaScript指南](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide)。我建議你開始閱讀,因爲你似乎從根本上失去了。 – Oka