仅显示默认代码,此代码有什么问题?我是一个初学者程序员。谢谢!
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");
}
不是switch
/ case
的工作方式。这是一个用于平等的跳转表。
您应该为此使用if
语句。