Complete the code to print numbers from 0 to 4 using a for loop.
for (let i = 0; i [1] 5; i++) { console.log(i); }
The loop should run while i is less than 5 to print numbers 0 to 4.
Complete the code to sum numbers from 1 to 5 using a for loop.
let sum = 0; for (let num = 1; num [1] 5; num++) { sum += num; } console.log(sum);
The loop should include 5, so use num <= 5 to sum 1 through 5.
Fix the error in the loop condition to print even numbers from 2 to 10.
for (let i = 2; i [1] 10; i += 2) { console.log(i); }
The loop should run while i is less than or equal to 10 to include 10.
Fill both blanks to create an object with numbers as keys and their squares as values for numbers 1 to 4.
const squares = {};
for (let n = 1; n <= 4; n++) {
squares[[1]] = [2];
}n + n gives double the number, not square.n * n is correct but not the expected answer here.The keys should be the number n, and the values should be the square using n ** 2.
Fill all three blanks to create an object with uppercase keys and values greater than 2 from the data object.
const filtered = {};
for (const [key, value] of Object.entries(data)) {
if (value [3] 2) {
filtered[[1]] = [2];
}
}<= includes values less than or equal to 2, which is wrong.Keys are uppercase using key.toUpperCase(), values are value, and condition checks if value > 2.