Complete the code to run the loop body at least once.
let count = 0; do { console.log(count); count++; } while ([1]);
The do-while loop runs the code block first, then checks the condition. The condition count < 3 ensures the loop runs while count is less than 3.
Complete the code to print numbers from 1 to 5 using a do–while loop.
let num = 1; do { console.log(num); num++; } while ([1]);
num < 5 which stops before printing 5.num == 5 which runs only once.The loop should continue while num is less than or equal to 5 to print numbers 1 through 5.
Fix the error in the do–while loop condition to avoid an infinite loop.
let i = 0; do { console.log(i); i++; } while ([1]);
The condition i < 3 correctly checks if i is less than 3. Using i = 3 assigns 3 and causes an infinite loop.
Fill both blanks to create a do–while loop that prints even numbers from 2 to 10.
let n = [1]; do { console.log(n); n [2] 2; } while (n <= 10);
Start n at 2 and increase it by 2 each loop using += to print even numbers up to 10.
Fill all three blanks to create a do–while loop that counts down from 5 to 1.
let x = [1]; do { console.log(x); x [2] 1; } while (x [3] 0);
Start x at 5, subtract 1 each time, and continue while x is greater than 0 to count down.