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))' –