1.
Day of the Week Switch Case (JavaScript)
------------------------------------------
Task:
- Take a character input (1-7), print the corresponding day of the week.
- Else print "Invalid input".
Sample Input: 5
Sample Output: Friday
---
2. JavaScript Array Output (Index Manipulation)
-----------------------------------------------
Code:
let x = [11, [15, 16], 12, "Codechef", 14];
x[1] = 12;
console.log(x);
Question: What is the output?
---
3. Difference Between Largest Even and Odd Number
--------------------------------------------------
Task:
- Input an integer n.
- Print difference between largest even and largest odd number from 1 to n.
Sample Input: 5
Sample Output: -1
Explanation:
- Array: [1, 2, 3, 4, 5]
- Largest Even = 4
- Largest Odd = 5
- Output = 4 - 5 = -1
---
4. While Loop Execution Count
-----------------------------
Code:
let x = 5;
while (x > 0) {
console.log(x);
x = x - 1;
}
Question: How many times will the loop execute?
Answer: 5 times
---
5. Count Number of Digits in a Number
-------------------------------------
Task:
- Given an integer N, calculate and print the number of digits.
Sample Input: 1543
Sample Output: 4
---
6. For Loop Output Guess
------------------------
Code:
for (let i = 1; i <= 3; i++) {
console.log("Hello");
i += 2;
}
Question: How many times does "Hello" print?
Answer: Once