Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to break out of the outer loop using a label.
Javascript
outerLoop: for (let i = 0; i < 3; i++) { for (let j = 0; j < 3; j++) { if (i === 1 && j === 1) { [1] outerLoop; } } }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'continue' instead of 'break' to exit the loop.
Forgetting to add the label after 'break'.
✗ Incorrect
The 'break' statement with a label exits the labeled loop immediately.
2fill in blank
mediumComplete the code to continue the outer loop when a condition is met.
Javascript
outer: for (let i = 0; i < 3; i++) { for (let j = 0; j < 3; j++) { if (j === 1) { [1] outer; } } }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'break' instead of 'continue' to skip iterations.
Not specifying the label after 'continue'.
✗ Incorrect
The 'continue' statement with a label skips to the next iteration of the labeled loop.
3fill in blank
hardFix the error in the labeled continue statement.
Javascript
outerLoop: for (let i = 0; i < 2; i++) { for (let j = 0; j < 2; j++) { if (i === j) { [1] outerLoop; } } }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Misspelling 'continue' as 'continuee'.
Using 'break' when 'continue' is needed.
✗ Incorrect
The correct keyword is 'continue' to skip to the next iteration of the labeled loop.
4fill in blank
hardFill both blanks to correctly use labeled break and continue in nested loops.
Javascript
outer: for (let i = 0; i < 3; i++) { inner: for (let j = 0; j < 3; j++) { if (i === 1 && j === 1) { [1] outer; } if (j === 2) { [2] inner; } } }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up 'break' and 'continue' keywords.
Using wrong labels or missing labels.
✗ Incorrect
Use 'break outer;' to exit the outer loop and 'continue inner;' to skip to the next iteration of the inner loop.
5fill in blank
hardFill all three blanks to create a labeled loop that breaks and continues correctly.
Javascript
outerLoop: for (let i = 0; i < 4; i++) { innerLoop: for (let j = 0; j < 4; j++) { if (i === 2 && j === 2) { [1] outerLoop; } if (j === 3) { [2] innerLoop; } console.log(i, j); } if (i === 3) { [3]; } }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'break' without label to exit outer loop.
Using 'continue' without label to skip inner loop.
Confusing 'return' with 'break' or 'continue'.
✗ Incorrect
Use 'break outerLoop;' to exit the outer loop, 'continue innerLoop;' to skip inner loop iterations, and 'return;' to exit the function.