Skip to main content

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. 1

    Stop at a match

    easy10 min

    Scan 1..10 and stop at the first number divisible by 4. Show it.

  2. 2

    Count until break

    easy10 min

    Count how many iterations run before breaking at 3.

  3. 3

    Skip with continue

    easy10 min

    Sum 1..5 but skip the number 3.

  4. 4

    Find an item in a list

    easy10 min

    Find "Grace" in the list and show her position (1-based).

  5. 5

    Break out of a search early

    medium10 min

    Stop scanning as soon as a negative number appears and report it.

Find the bug(5)

  1. 1

    Fix the missing break

    easy8 min

    Without break the loop keeps going and reports the last match.

  2. 2

    Fix break used instead of continue

    easy8 min

    break stops the whole loop when only one value should be skipped.

  3. 3

    Fix the break placed too early

    easy8 min

    Breaking before the work happens means nothing is counted.

  4. 4

    Fix the zero-based position

    easy8 min

    The reported position is off by one.

  5. 5

    Fix the wrong comparison in the search

    easy8 min

    The 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