Caixa de interruptor JS
switch(expression) {
case x:
// code block
break;
case y:
// code block
break;
default:
// code block
}
Grotesque Grebe
switch(expression) {
case x:
// code block
break;
case y:
// code block
break;
default:
// code block
}
//javascript multiple case switch statement
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";
}
//darkOrLight="Light"
switch(type) {
case "SomeString":
// Functionality
break;
case "OtherString":
// Functionality
break;
default:
// Functionality
break;
}
let x = 3;
switch(x) {
case 1:
console.log("You entered 1");
break;
case 2:
console.log("You entered 2");
break;
default:
console.log("You entered: "+ x);
}
switch (new Date().getDay()) {
case 0:
day = "Sunday";
break;
case 1:
day = "Monday";
break;
case 2:
day = "Tuesday";
break;
case 3:
day = "Wednesday";
break;
case 4:
day = "Thursday";
break;
case 5:
day = "Friday";
break;
case 6:
day = "Saturday";
}
console.log(day);
switch(variable/expression) {
case value1:
// body of case 1
break;
case value2:
// body of case 2
break;
case valueN:
// body of case N
break;
default:
// body of default
}