我正在学习如何编码,所以我有一个问题? [重复]

问题描述 投票:-1回答:1

仅显示默认代码,此代码有什么问题?我是一个初学者程序员。谢谢!

   let age=30;
    switch (age){
        case age > 23:
        console.log("you are allowed to drink beer");
        break;
        case age < 23:
        console.log("you are not allowed to drink or smoke");
        break;
        case age >= 23:
        console.log("you can smoke or drink from next year");
        break;
        default:
        console.log("check your age first in the birth certificate");
    }
javascript switch-statement
1个回答
0
投票

不是switch / case的工作方式。这是一个用于平等的跳转表。

您应该为此使用if语句。

© www.soinside.com 2019 - 2024. All rights reserved.