Skip to main content

JavaScript Callback Functions — exercises and bug fixes

5 hands-on exercises and 5 find-the-bug challenges for the JavaScript Callback Functions 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

    Pass a callback

    easy10 min

    Pass a function to another function and show what it returns.

  2. 2

    A named callback

    easy10 min

    Pass a named function to map to double each value, then join with commas.

  3. 3

    A callback with an argument

    easy10 min

    Call the callback three times with the count, collecting the values.

  4. 4

    Filter with a callback

    easy10 min

    Use filter with a callback to keep numbers above 4, then join with commas.

  5. 5

    Transform with a callback

    medium10 min

    Write a process function that applies a callback to every item. Square them and join with commas.

Find the bug(5)

  1. 1

    Fix the callback called too early

    easy8 min

    The brackets run the function and pass its result instead.

  2. 2

    Fix the wrong operation

    easy8 min

    The callback adds 2 instead of doubling.

  3. 3

    Fix the ignored argument

    easy8 min

    The callback is given the count but never uses it.

  4. 4

    Fix the inverted filter

    easy8 min

    The condition keeps the wrong numbers.

  5. 5

    Fix the callback that returns nothing

    easy8 min

    Without a return the collected values are all undefined.

Ready to write the code?

The editor, the automatic checks and the worked solutions open up with an account.

Open the workspace