-
Notifications
You must be signed in to change notification settings - Fork 0
/
switch.js
108 lines (106 loc) · 2.29 KB
/
switch.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
function simpleSwitch()
{
let productId = 3;
switch(productId)
{
default:
console.log("Unknown Product");
break;
case 1:
console.log("Product 1");
break;
case 2:
console.log("Product 2");
break;
}
}
function multipleCase()
{
let color="Red";
switch(color)
{
case "Red":
case "Pink":
console.log("The color is red");
break;
case "Blue":
case "Light Blue":
case "Dark Blue":
console.log("The color is blue");
case "Gray":
case "Grey":
console.log("The color is grey");
break;
default:
console.log("Unknown color");
break;
}
}
function forgetABreak()
{
let productId = 2;
switch(productId)
{
case 1:
console.log("HL Road Frame=Black, 58");
break;
case 2:
console.log("Sport-100 Helmet, Red");
case 3:
console.log("Mountain Bike Socks, M");
break;
default:
console.log("Unknown Product");
break;
}
}
function strictComparison()
{
let productId = "2";
switch(productId)
{
case 1:
console.log("HL Road Frame=Black, 58");
break;
case 2:
console.log("Sport-100 Helmet, Red");
break;
case 3:
console.log("Mountain Bike Socks, M");
break;
default:
console.log("Unknown Product");
break;
}
}
function blockScopeFix()
{
let productId = 2;
switch(productId)
{
case 1:
{
let message = "HL Road Frame=Black, 58";
console.log(message);
break;
}
case 2:
{
let message = "Sport-100 Helmet, Red";
console.log(message);
break;
}
case 3:
{
let message = "Mountain Bike Socks, M";
console.log(message);
break;
}
default:
{
let message = "Unknown Product";
console.log(message);
break;
}
}
}