Complete the code to print numbers from 0 to 4.
for(let i = 0; i [1] 5; i++) { console.log(i); }
We use < because the loop runs while i is less than 5, so it stops before 5.
Complete the code to check if a number is within the boundary 1 to 10 (inclusive).
if(num [1] 1 && num [2] 10) { console.log('Inside boundary'); }
We use >= 1 and <= 10 to include both 1 and 10 in the boundary.
Fix the error in the loop boundary to avoid an infinite loop.
let count = 0; while(count [1] 5) { console.log(count); count--; }
Using > makes the condition count > 5 false from the start (0 > 5 is false), so the loop does not enter and avoids being infinite. With < or <=, since count is decremented, it moves further away from the exit condition, causing an infinite loop.
Fill both blanks to create a dictionary of word lengths for words longer than 3 characters.
const words = ['apple', 'bat', 'carrot', 'dog']; const lengths = Object.fromEntries(words.filter(w => w.length > 3).map(word => [[1], [2]]));
We use word as the key and word.length as the value to map each word to its length.
Fill all three blanks to create an object with uppercase keys and values greater than 0.
const data = { a: 1, b: 0, c: 3 };
const result = Object.fromEntries(Object.entries(data).filter(([k,v]) => v > 0).map(([[3],v]) => [[1], [2]]));We use k.toUpperCase() as the new key, v as the value, and k as the variable for keys in the loop.