-
Notifications
You must be signed in to change notification settings - Fork 0
/
day2.js
94 lines (59 loc) · 2.76 KB
/
day2.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
91
92
93
94
// Activity 1: Arithmetic Operations
// Task 1: Write a program to add two numbers and log the result to the console.
let num1 = 9;
let num2 = 6;
console.log(num1 + num2); //output: 15
// Task 2: Write a program to subtract two numbers and log the result to the console.
console.log(num1 - num2); //output: 2
// Task 3: Write a program to multiply two numbers and log the result to the console.
let num3 = 9;
let num4 = 2;
let multiply = num3 * num4
console.log(multiply); //output: 18
// Task 4: Write a program to divide two numbers and log the result to the console.
let divide = num3 / num4
console.log(divide); //output: 4.5
// Task 5: Write a program to find the remainder when one number is divided by another and log the result to the console.
let remainder = num3 % num4;
console.log(remainder); //output: 1
// Activity 2: Assignment Operators
// Task 6: Use the `+=` operator to add a number to a variable and log the result to the console.
let D1 = 2;
D1 += 3
console.log(D1); //output: 5
// Task 7: Use the `-=` operator to subtract a number from a variable and log the result to the console.
D1 -= 4;
console.log(D1); //output: 1
// Activity 3: Comparison Operators
// Task 8: Write a program to compare two numbers using `>` and `<` and log the result to the console.
let num5 = 6;
let num6 = 9;
if(num5 < num6){
console.log("num6 is greater than num5");
} else {
console.log("num5 is greater than num6"); //output: num6 is greater than num5
}
// Task 9: Write a program to compare two numbers using `>=` and `<=` and log the result to the console.
let num7 = 9;
let num8 = 5;
if (num8 >= num7) {
console.log("num8 is greater than or equal to num7");
} else {
console.log("num7 is greater than or equal to num8"); //output: num7 is greater than or equal to num8
}
// Task 10: Write a program to compare two numbers using `==` and `===` and log the result to the console.
// Activity 4: Logical Operators
// - Task 11: Write a program that uses the && operator to combine two conditions and log the result to the console.
const z = 5, y = 3;
console.log((z < 6) && (y < 5));
// - Task 12: Write a program that uses the || operator to combine two conditions and log the result to the console.
let x = 3;
console.log((x > 2) || (x > 5)); // true
console.log((x > 3) || (x < 0)); // false
// - Task 13: Write a program that uses the ! operator to negate a condition and log the result to the console.
console.log(!(x < 2)); // true
// Activity 5: Ternary Operator
// - Task 14: Write a program that uses the ternary operator to check if a number is positive or negative and log the result to the console.
let number = 6
let posORneg = number > 0 ? 'positive' : 'negative';
console.log(posORneg); //positive