0
0
Javascriptprogramming~10 mins

Do–while loop in Javascript - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to run the loop body at least once.

Javascript
let count = 0;
do {
  console.log(count);
  count++;
} while ([1]);
Drag options to blanks, or click blank then click option'
Acount = 3
Bcount < 3
Ccount++
Dcount > 3
Attempts:
3 left
💡 Hint
Common Mistakes
Using assignment (=) instead of comparison (== or <).
Using increment (count++) in the condition.
2fill in blank
medium

Complete the code to print numbers from 1 to 5 using a do–while loop.

Javascript
let num = 1;
do {
  console.log(num);
  num++;
} while ([1]);
Drag options to blanks, or click blank then click option'
Anum <= 5
Bnum < 5
Cnum == 5
Dnum > 5
Attempts:
3 left
💡 Hint
Common Mistakes
Using num < 5 which stops before printing 5.
Using equality num == 5 which runs only once.
3fill in blank
hard

Fix the error in the do–while loop condition to avoid an infinite loop.

Javascript
let i = 0;
do {
  console.log(i);
  i++;
} while ([1]);
Drag options to blanks, or click blank then click option'
Ai > 3
Bi = 3
Ci++ < 3
Di < 3
Attempts:
3 left
💡 Hint
Common Mistakes
Using assignment (=) instead of comparison (== or <).
Putting increment (i++) inside the condition.
4fill in blank
hard

Fill both blanks to create a do–while loop that prints even numbers from 2 to 10.

Javascript
let n = [1];
do {
  console.log(n);
  n [2] 2;
} while (n <= 10);
Drag options to blanks, or click blank then click option'
A2
B+=
C-=
D0
Attempts:
3 left
💡 Hint
Common Mistakes
Starting at 0 instead of 2.
Using subtraction instead of addition.
5fill in blank
hard

Fill all three blanks to create a do–while loop that counts down from 5 to 1.

Javascript
let x = [1];
do {
  console.log(x);
  x [2] 1;
} while (x [3] 0);
Drag options to blanks, or click blank then click option'
A5
B-=
C>
D<
Attempts:
3 left
💡 Hint
Common Mistakes
Using addition instead of subtraction.
Using less than comparison which would cause an infinite loop.