Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to stop the loop when i equals 3.
Javascript
for (let i = 0; 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 'continue' instead of 'break' which skips the current iteration but does not stop the loop.
Using 'return' inside a loop without a function context causes errors.
✗ Incorrect
The break statement stops the loop immediately when the condition is met.
2fill in blank
mediumComplete the code to exit the while loop when count reaches 5.
Javascript
let count = 0; while (true) { if (count === 5) { [1]; } console.log(count); count++; }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'continue' which skips the rest of the loop but does not stop it.
Using 'exit' or 'stop' which are not valid JavaScript keywords.
✗ Incorrect
The break statement exits the infinite while loop when count is 5.
3fill in blank
hardFix the error in the code to stop the loop when num is 10.
Javascript
for (let num = 0; num < 20; num++) { if (num === 10) { [1]; } console.log(num); }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'continue' which skips the current iteration but does not stop the loop.
Using invalid keywords like 'exit' or 'stop'.
✗ Incorrect
Using break correctly stops the loop when num reaches 10.
4fill in blank
hardFill both blanks to stop the loop when the letter is 'c'.
Javascript
const letters = ['a', 'b', 'c', 'd']; for (let i = 0; i < letters.length; i++) { if (letters[i] [1] 'c') { [2]; } console.log(letters[i]); }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '!=' or '!==' instead of '===' for equality check.
Using 'continue' which skips iteration but does not stop the loop.
✗ Incorrect
The condition letters[i] === 'c' checks for 'c', and break stops the loop when found.
5fill in blank
hardFill all three blanks to stop the loop when the number is greater than 7.
Javascript
const numbers = [3, 5, 8, 10]; for (const num [1] numbers) { if (num [2] 7) { [3]; } console.log(num); }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'in' instead of 'of' to loop over array values.
Using '<' instead of '>' in the condition.
Using 'continue' instead of 'break' to stop the loop.
✗ Incorrect
Use for...of to loop over array values, check if num > 7, and use break to stop the loop.