forked from pirple/Keeping-Up-With-the-Javascripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Switch Statements.js
executable file
·93 lines (83 loc) · 1.5 KB
/
Switch Statements.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
/*
* Switch Statements
*
*/
/*
switch(expression) {
case value1:
statement to be executed when result of expression
matches value1
break;
case value2:
...
break;
case value3:
...
break;
default:
break;
}
*/
function fruitLogger(fruit) {
switch(fruit) {
case "apple":
case "orange":
case "banana":
console.log("Great! I love fruit.");
break;
default:
console.log("I didn't understand that but sure :D");
break;
}
console.log("Broke out of switch statement");
}
function numChecker(num) {
let value;
switch(num) {
case 0:
case 1:
case 2:
value = "low range";
setVolume(value);
break;
case 3:
case 4:
case 5:
value = "mid range";
setVolume(value);
break;
case 6:
case 7:
case 8:
value = "high range";
setVolume(value);
break;
default:
value = "Input number between 0-8";
console.log(value);
break;
}
}
function setVolume(n) {
console.log("Volume set at " + n );
}
const donutPicker = (flav) => {
switch(flav) {
case "s":
return "sprinkles";
case "c":
return "chocolate glazed";
case "b":
return "bear claw";
default :
return null;
}
}
const donuts = (selection) => {
const selectedDonut = donutPicker(selection);
if (!selectedDonut) {
console.log("Incorrect selection");
} else {
console.log("You have selected " + selectedDonut);
}
}