-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconditionals.js
90 lines (71 loc) · 1.35 KB
/
conditionals.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
let a = 9;
let b = 32;
if (a > b) {
console.log('a is greater than b');
} else if (a === b) {
console.log('a is equal to b');
} else {
console.log('a is less than b');
}
if ((a + b) > (a * b - 248)) {
console.log('The condition is true');
} else {
console.log('The condition is false');
}
// && = AND
// || = OR
if ((true) && (true)) {
console.log('true');
} else {
console.log('false');
}
if ((true) && (false)) {
console.log('true');
} else {
console.log('false');
}
if ((true) || (false)) {
console.log('true');
} else {
console.log('false');
}
let isDarkOutside = true;
if (isDarkOutside) {
console.log('It is dark outside');
} else {
console.log('It is daylight');
}
// switch statement
let color = 'black';
switch(color) {
case 'yellow':
console.log('Yellow');
break;
case 'green':
console.log('Green');
break;
case 'red':
console.log('Red');
break;
default:
console.log('We couldn\'t determine the color');
}
// Loops
// while Loop
console.log('While loop');
let counter = 5;
while (counter <= 10) {
console.log(`The value is ${counter++}`);
}
// Do while Loop
console.log('Do while loop');
counter = 5;
do {
console.log(`The value is ${counter}`);
counter++;
} while (counter <= 10);
// for Loop
console.log('For Loop');
for (let i = 5; i <= 10; i++) {
console.log(`The value is ${i}`);
}