可以使用嵌套的switch语句来比较多个变量的不同组合。以下是一个示例,其中有两个变量:day和meal:
let day = "Monday";
let meal = "dinner";
switch (day) {
case "Monday":
case "Tuesday":
case "Wednesday":
case "Thursday":
case "Friday":
switch (meal) {
case "breakfast":
console.log("Cereal and milk");
break;
case "lunch":
console.log("Soup and sandwich");
break;
case "dinner":
console.log("Steak and potatoes");
break;
default:
console.log("Invalid meal time");
break;
break;
case "Saturday":
console.log("Brunch");
break;
case "Sunday":
console.log("Pancakes");
break;
default:
console.log("Invalid day");
break;