Skip to content

Commit a387fe7

Browse files
committed
Updated 11_challenge.js with new code for compound variables calculator and added a new challenge for checking if a number is a palindrome.
1 parent ba41679 commit a387fe7

File tree

1 file changed

+49
-20
lines changed

1 file changed

+49
-20
lines changed
Lines changed: 49 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
// 11_challenge.js
22

33
/*
4-
Challenge: Compound Variables Calculator
4+
5+
Challenge 1 : Compound Variables Calculator
56
67
Objective: Create a program that uses all types of variables (number, string, boolean) and performs compound assignment operations on them.
78
@@ -14,35 +15,63 @@ Instructions:
1415
Files to Reference: 01A_compound_assignment.js, 01_variables.js, 02_declare_intialize.js, 03_string_vars.js
1516
*/
1617

18+
// Number operations
1719
let myNum = 20;
20+
21+
myNum += 5; // add 5 to myNum
22+
console.log(myNum); // Output: 25
23+
24+
myNum -= 3; // subtract 3 from myNum
25+
console.log(myNum); // Output: 22
26+
27+
myNum *= 2; // multiply myNum by 2
28+
console.log(myNum); // Output: 44
29+
30+
myNum /= 4; // divide myNum by 4
31+
console.log(myNum); // Output: 11
32+
33+
myNum %= 4; // get the remainder of myNum divided by 4
34+
console.log(myNum); // Output: 3
35+
36+
// String operations
1837
let myStr = "Hello";
38+
myStr += " World"; // concatenate myStr with " World"
39+
console.log(myStr);
40+
41+
// Boolean operations
1942
let myBool = false;
2043

21-
// Number operations
44+
myBool &&= false; // logical AND operation
45+
console.log("After &&= false, bool:", myBool); // Output: false
2246

23-
myNum += 5;
24-
console.log(myNum) // Output : 25
47+
myBool ||= true; // logical OR operation
48+
console.log("After ||= true, bool:", myBool); // Output: true
2549

26-
myNum -= 3;
27-
console.log(myNum) // Output: 22
2850

29-
myNum *= 2;
30-
console.log(myNum) // Output: 44
51+
/*
52+
Challenge 2 : Check if Number is a Palindrome
3153
32-
myNum /= 4;
33-
console.log(myNum) // Output: 11
54+
Objective: Write a program that takes a number as input and checks if it is a palindrome (a number that reads the same forwards and backwards).
3455
35-
myNum %= 4;
36-
console.log(myNum) // Output: 3
56+
Instructions:
3757
38-
// String operations
58+
- Write a function that takes a number as input and checks if it is a palindrome.
59+
- Use the function to check if a number is a palindrome.
60+
- Print the result to the console.
3961
40-
myStr += " World";
41-
console.log(myStr)
62+
Files to Reference: 01A_compound_assignment.js, 01_variables.js, 02_declare_intialize.js, 03_string_vars.js
63+
*/
4264

43-
// Boolean operations
44-
myBool &&= false;
45-
console.log("After &&= false, bool:", myBool); // Output: false
65+
function checkIfPalindrome(num) {
66+
let str = num.toString();
67+
let reversedStr = str.split("").reverse().join("");
68+
69+
if (str === reversedStr) {
70+
return true;
71+
}
72+
else if (str !== reversedStr) {
73+
return false;
74+
}
75+
}
4676

47-
myBool ||= true;
48-
console.log("After ||= true, bool:", myBool); // Output: true
77+
console.log(checkIfPalindrome(161)); // Output: true

0 commit comments

Comments
 (0)