Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to skip the current loop iteration when the number is 3.
Javascript
for (let i = 1; i <= 5; i++) { if (i === 3) { [1]; } console.log(i); }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'break' instead of 'continue' stops the entire loop.
Using 'return' inside a loop without a function causes errors.
✗ Incorrect
The 'continue' statement skips the current iteration and moves to the next one in the loop.
2fill in blank
mediumComplete the code to print only odd numbers from 1 to 5 using continue.
Javascript
for (let i = 1; i <= 5; i++) { if (i % 2 === 0) { [1]; } console.log(i); }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'break' stops the loop entirely.
Using 'skip' is not a valid JavaScript statement.
✗ Incorrect
Using 'continue' skips even numbers and prints only odd numbers.
3fill in blank
hardFix the error in the loop to skip printing number 4.
Javascript
for (let num = 1; num <= 5; num++) { if (num === 4) { [1]; } console.log(num); }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'break' stops the entire loop.
Using 'return' outside a function causes errors.
✗ Incorrect
The 'continue' statement skips printing number 4 and continues the loop.
4fill in blank
hardFill both blanks to skip even numbers and print only odd numbers from 1 to 6.
Javascript
for (let i = 1; i <= 6; i++) { if (i [1] 2 === 0) { [2]; } console.log(i); }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '===' instead of '%' for checking even numbers.
Using 'break' instead of 'continue'.
✗ Incorrect
The modulus operator '%' checks for even numbers, and 'continue' skips them.
5fill in blank
hardFill all three blanks to skip numbers divisible by 3 and print others from 1 to 9.
Javascript
for (let n = 1; n <= 9; n++) { if (n [1] 3 [2] 0) { [3]; } console.log(n); }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'break' instead of 'continue'.
Using '!== 0' instead of '=== 0' to check divisibility.
✗ Incorrect
Use '%' to get remainder, '===' to check equality to zero, and 'continue' to skip divisible numbers.