小编Per*_*ner的帖子

(如何)我可以在switch语句中使用'或'吗?

以下代码是否正确:

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;
}
Run Code Online (Sandbox Code Playgroud)

我尝试过这个.但它没有按照我的意愿行事.如果输入是'地狱没有'或'地狱是的',它运作良好,但所有后来的字符串都被忽略了!

javascript switch-statement

4
推荐指数
1
解决办法
79
查看次数

标签 统计

javascript ×1

switch-statement ×1