JavaScript break Statement — exercises and bug fixes
5 hands-on exercises and 5 find-the-bug challenges for the JavaScript break Statement lesson. Every one is checked automatically in the browser — write the code, run it, and the tests tell you what still fails.
Exercises(5)
- 1
Stop at a match
easy10 minScan 1..10 and stop at the first number divisible by 4. Show it.
- 2
Count until break
easy10 minCount how many iterations run before breaking at 3.
- 3
Skip with continue
easy10 minSum 1..5 but skip the number 3.
- 4
Find an item in a list
easy10 minFind "Grace" in the list and show her position (1-based).
- 5
Break out of a search early
medium10 minStop scanning as soon as a negative number appears and report it.
Find the bug(5)
- 1
Fix the missing break
easy8 minWithout break the loop keeps going and reports the last match.
- 2
Fix break used instead of continue
easy8 minbreak stops the whole loop when only one value should be skipped.
- 3
Fix the break placed too early
easy8 minBreaking before the work happens means nothing is counted.
- 4
Fix the zero-based position
easy8 minThe reported position is off by one.
- 5
Fix the wrong comparison in the search
easy8 minThe test looks for the wrong condition and never breaks.
Ready to write the code?
The editor, the automatic checks and the worked solutions open up with an account.
Open the workspace