/
conditionals.js
52 lines (33 loc) · 988 Bytes
/
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
//Exercise 1 - conditionals (if)
const raining = true;
const cold = true;
if(raining) {
console.log("Don't forget your umbrella!");
}
if (cold) {
console.log("Make sure you pick out a scarf!");
}
// Exercise 2 - conditionals (else if)
const temperature = 12;
if(temperature < 0) {
console.log("Make sure you pick out a scarf!");
} else if (temperature < 15) {
console.log("Short sleeves are fine.");
} else {
console.log("Short sleeves are fine.");
}
console.log("Now you're ready to go outside!");
//Exercise 3 - Logical Operators (AND)
const isCitizen = true;
const age = 26;
if (isCitizen && age > 18) {
console.log("You are eligible to vote.");
}
//Exercise 4 - Logical Operators (OR)
if(temperature < -40 || temperature > 40) {
console.log("Maybe going outside isn't such a great idea...");
}
//Exercise 5 - Logical Operators (NOT)
if(!raining) {
console.log("Leave your umbrella at home!");
}