-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathswitch_vs_elseif.js
More file actions
44 lines (41 loc) · 894 Bytes
/
switch_vs_elseif.js
File metadata and controls
44 lines (41 loc) · 894 Bytes
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
//Else if and Switch statement
//suppose 40 out of 50 is the pass mark. if example:
var result = 39;
//var result= 45;
if (result>40){
console.log('You passed the test');
}
else{
console.log("You failed the test");
}
//Else if example
//var place = 'first';
//var place = "second"
/*var place = "third"
if (place=="first"){
console.log("Gold medal");
}
else if (place=="second"){
console.log('silver medal');
}
else if (place=="third"){
console.log('Bronze medal');
}
else{
console.log("No medal")
}*/
//BUt if in the above example there are large number of options such as 10. That's when switch is preferred.eg;
var place= "fourth";
switch(place){
case("first"):
console.log("GOld medal");
break;
case("second"):
console.log("Silver medal");
break;
case("third"):
console.log("Bronze medal");
break;
default:
console.log("No medal");
}