forked from loiane/javascript-datastructures-algorithms
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path06-ConditionalStatements.js
executable file
·51 lines (46 loc) · 1002 Bytes
/
06-ConditionalStatements.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
/* Example 01 - if */
var num = 1;
if (num === 1) {
console.log("num is equal to 1");
}
/* Example 02 - if-else */
var num = 0;
if (num === 1) {
console.log("num is equal to 1");
} else {
console.log("num is not equal to 1, the value of num is " + num);
}
/* Example 03 - if-else-if-else... */
var month = 5;
if (month === 1) {
console.log("January");
} else if (month === 2){
console.log("February");
} else if (month === 3){
console.log("March");
} else {
console.log("Month is not January, February or March");
}
/* Example 04 - switch */
var month = 5;
switch(month) {
case 1:
console.log("January");
break;
case 2:
console.log("February");
break;
case 3:
console.log("March");
break;
default:
console.log("Month is not January, February or March");
}
/* Example 05 - ternary operator - if..else */
if (num === 1){
num--;
} else {
num++;
}
//is the same as
(num === 1) ? num-- : num++;