-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathCh 2 Expression & Conditional Statement Practice Set.js
More file actions
67 lines (48 loc) · 1.26 KB
/
Ch 2 Expression & Conditional Statement Practice Set.js
File metadata and controls
67 lines (48 loc) · 1.26 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
64
65
// Ch 2 Expression & Conditional Statement Practice Set
// Q1) Use Logical Operator To Find Whether The Age Of a Person Lies Between 10 & 20.
let age = 15;
if (age >= 10 && age <= 20) {
console.log("The age is between 10 and 20.");
} else {
console.log("The age is not between 10 and 20.");
}
// Q2) Demonstrate The Use Of Switch Statement In JS With an Example.
let day = 3;
let dayName;
switch (day) {
case 1:
dayName = "Monday";
break;
case 2:
dayName = "Tuesday";
break;
case 3:
dayName = "Wednesday";
break;
case 4:
dayName = "Thursday";
break;
case 5:
dayName = "Friday";
break;
case 6:
dayName = "Saturday";
break;
case 7:
dayName = "Sunday";
break;
default:
dayName = "Invalid day";
}
console.log(dayName);
// Q3) Write JS Program To Find Whether the Number Is Divisible By 2 And 3.
let number = 12;
if (number % 2 === 0 && number % 3 === 0) {
console.log(number + " is divisible by both 2 and 3.");
} else {
console.log(number + " is not divisible by both 2 and 3.");
}
// Q4) Print "You Can Drive" Or "You Can't Drive" Based On Age Being Greater Than 18 Using Ternary Operator
let age = 20;
let canDrive = age > 18 ? "You can drive." : "You can't drive.";
console.log(canDrive);