憋屈一個javascript開關分配。我對這些東西還是比較陌生的,但似乎無法在課本或在線上找到任何可以使本程序正常工作的東西。任務是切換if語句來切換代碼。任何幫助或建議將不勝感激。JavaScript的switch語句的年齡範圍
var myAge = prompt("Enter your age:", "30");
switch (myAge) {
case myAge! >= 0:
case myAge <= 10:
document.write("myAge is NOT between 0 and 10 <br />");
case myAge >= 0:
case myAge <= 10:
document.write("myAge is between 0 and 10 ");
break;
case myAge >= 80:
case mmyAge <= 10:
document.write("myAge is 80 or above or 10 or below ");
break;
case myAge >= 30:
case myAge <= 39:
document.write("myAge is between 30 and 39 ");
break;
case myAge >= 80:
case myAge <= 89:
document.write("myAge is between 80 and 89 ");
break;
}
你錯過了一個破';!'在第一種情況下 –
你需要用'開關(真){'來匹配您的布爾表達式的情況下和'>'是不是有效的運營商 –
@Community ...很抱歉,但是這顯然是一個不同的問題...讓我們把它放在這樣:你認爲什麼cameragrl37從87輸入期望...... 我會說,他預計3封郵件......這個?不能寫入一個開關! – fedeghe