-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path03_ControlStructures.js
More file actions
63 lines (52 loc) · 1.59 KB
/
03_ControlStructures.js
File metadata and controls
63 lines (52 loc) · 1.59 KB
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
// Introduction to JavaScript
// Lesson 3: Control Structures - Conditional Statements
// Conditional statements allow us to make decisions in our code by executing different code blocks based on certain conditions.
// The 'if-else' statement is one of the most common forms of control structures.
// Example of 'if-else'
let number = 10;
if (number > 0) {
console.log('The number is positive');
} else {
console.log('The number is not positive');
}
// Another control structure is the 'switch' statement, which is used for multiple conditions.
// Example of 'switch'
let color = 'blue';
switch (color) {
case 'red':
console.log('The color is red');
break;
case 'blue':
console.log('The color is blue');
break;
default:
console.log('Color not recognized');
}
// CHALLENGES
// CHALLENGE 1: Fix the 'if-else' statement
// The code below should print "Adult" if the age is 18 or over, and "Minor" if under 18.
let age = 16;
if (age >= 18) {
console.log('Minor'); // TODO: This line is incorrect. Fix the output messages.
} else {
console.log('Adult'); // TODO: This line is also incorrect.
}
// CHALLENGE 2: Complete the 'switch' statement
// Add a case in the switch statement for when the 'day' is "Wednesday".
let day = 'Wednesday';
switch (day) {
case 'Monday':
console.log("It's Monday");
break;
// TODO: Add a case here for "Wednesday".
default:
console.log('Some other day');
}
console.log(age);
console.log(day);
module.exports = {
age,
day,
};
// To run this JavaScript file, use the command 'node 03_ControlStructures.js' in your terminal.
// ✅ REMOVE THIS LINE to check your work