or condition in switch case code example
Example 1: javascript switch statement multiple cases
var color = "yellow";
var darkOrLight="";
switch(color) {
case "yellow":case "pink":case "orange":
darkOrLight = "Light";
break;
case "blue":case "purple":case "brown":
darkOrLight = "Dark";
break;
default:
darkOrLight = "Unknown";
}
Example 2: java switch multiple values
switch (num) {
case 5:
case 2:
case 3:
System.out.println("5,2,3");
break;
case 4:
case 6:
System.out.println("4,6");
break;
case 1:
System.out.println("1");
break;
default:
System.out.println("Inavlid number");
break;
}
Example 3: switch case in
function whatToDrink(time){
var drink ;
switch (time) {
case "morning":
drink = "Tea";
break;
case "evening":
drink = "Shake";
break;
default:
drink="Water";
}
return drink;
}
console.log(whatToDrink("morning"))
console.log(whatToDrink("evening"))
console.log(whatToDrink("night"))
console.log(whatToDrink("daytime"))