0
0
Javascriptprogramming~10 mins

Break statement 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 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'
Abreak
Breturn
Ccontinue
Dstop
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.
2fill in blank
medium

Complete 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'
Acontinue
Bbreak
Cexit
Dstop
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.
3fill in blank
hard

Fix 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'
Acontinue
Bexit
Cbreak
Dstop
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'.
4fill in blank
hard

Fill 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'
A===
B!==
Cbreak
Dcontinue
Attempts:
3 left
💡 Hint
Common Mistakes
Using '!=' or '!==' instead of '===' for equality check.
Using 'continue' which skips iteration but does not stop the loop.
5fill in blank
hard

Fill 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'
Aof
B>
Cbreak
Din
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.