var speed = prompt("Do you know how to type?");
speed = speed.toLowerCase();
if (speed === "yes") {
var howFast = prompt("what is your wpm?(the answer must be a number between 1 and 200");
switch(howFast) {
case (howFast <= 10):
console.log("you are a snail! practice and type at least 20 wpm, then try this again.");
break;
case (howFast <= 30):
console.log("you are still pretty slow, but you're getting there!");
break;
case (howFast <= 50):
console.log("you are getting there, keep trying");
break;
case (howFast <= 90):
console.log("WoW! Excellent job! Your tenacity has paid off");
break;
case (howFast > 90):
console.log("you are a megaracer! congratulations!");
break;
default:
console.log("DOES NOT COMPUTE... You're either superfast or playing around!");
}
} else { alert("learn how to type and comeback.");}
我想在javascript中編寫一個簡單的switch語句來詢問用戶他們的打字速度。令我沮喪的是,當這段代碼執行最終警報時,我總是回到默認情況。請告訴我我做錯了什麼!簡單開關語句
試試'switch(parseInt(howFast))' –