1switch(expression) {
2 case x:
3 // code block
4 break;
5 case y:
6 // code block
7 break;
8 default:
9 // code block
10}
1switch (a) {
2 case 1:
3 alert('case 1 executed');
4 break;
5 case 2:
6 alert("case 2 executed");
7 break;
8 case 3:
9 alert("case 3 executed");
10 break;
11 case 4:
12 alert("case 4 executed");
13 break;
14 default:
15 alert("default case executed");
16}
1//javascript multiple case switch statement
2var color = "yellow";
3var darkOrLight="";
4switch(color) {
5 case "yellow":case "pink":case "orange":
6 darkOrLight = "Light";
7 break;
8 case "blue":case "purple":case "brown":
9 darkOrLight = "Dark";
10 break;
11 default:
12 darkOrLight = "Unknown";
13}
14
15//darkOrLight="Light"
1switch(type) {
2 case "SomeString":
3 // Functionality
4 break;
5 case "OtherString":
6 // Functionality
7 break;
8 default:
9 // Functionality
10 break;
11}
1let color = "black";
2
3switch(color){
4 case "red":
5 console.log("color is red");
6 break;
7 case "white":
8 console.log("color is white");
9 break;
10 case "black":
11 console.log("color is black");
12 break;
13 default:
14 console.log("unknow color");
15}
1function caseInSwitch(val) {
2 var answer = "";
3 // Only change code below this line
4switch(val) {
5 case 1:
6 answer = "alpha";
7 console.log(answer);
8 break;
9 case 2:
10 answer = "beta";
11 break;
12 case 3:
13 answer = "gamma";
14 break;
15 case 4:
16 answer = "delta";
17 break;
18}
19
20
21 // Only change code above this line
22 return answer;
23}
24
25caseInSwitch(1);
26