以下代码是否正确:
var user = prompt("Is programming awesome?").toUpperCase();
switch (user) {
case 'HELL YEAH' || 'YES' || 'YEAH' || 'YEP' || 'YEA':
console.log("That's what I'd expected!");
break;
case 'KINDA'||'CANT SAY':
console.log("Oh, you'd like it when you'll be a pro!");
break;
case 'HELL NO'||'NO'||'NAH'||'NOPE'||'NA':
console.log("You can't say that!");
break;
default:
console.log("Wacha tryna say mate?");
break;
}
我尝试过了,但它并没有按照我的期望工作。如果输入是“hell no”或“hell yeah”,那么它可以正常工作,但之后的所有字符串都被忽略了!