JAVASCRIPT IN PRACTICE

Find and fix the bug

Find and fix the bug - the starter contains a defect. Trains reading other people's code and debugging.

  • Tracing values
  • Conditions and loops
  • Bug fixes
Preview the first challenge →

Solving requires a free account.

Selected challenges to get started

Pick a challenge and explore the rules through a concrete example.

Warm-up

Find maximum

Fix the function finding the max number. The array is non-empty and contains finite numbers. Check the loop bound: reading past the array does not produce a number.

Preview challenge → Free account required to solve
Warm-up

Bad loop

Fix the while loop: for an integer n ≥ 0, return numbers from n down to 1, excluding zero. Return [] for n=0.

Preview challenge → Free account required to solve
Warm-up

Fix the summation

This should sum 1..n but drops the last number. Fix it. n is an integer ≥ 0; the sum for 0 is 0.

Preview challenge → Free account required to solve

Ready for more?

Available challenges: 22.

See all challenges →

The full catalogue requires a free account.

How should you approach these challenges?

JavaScript debugging exercises develop your ability to read existing code and find the cause of incorrect behaviour. The workflow resembles handling a bug report: reproduce the issue, make a fix and check that other cases still work.

First reproduce the bug with the smallest example. Trace variable values, conditions and loop boundaries to find where the result diverges from expectations. Fix the cause and rerun all tests, including cases that already passed.

Explore an example: Find maximum →

Read the description without logging in. Solving requires a free account.