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
Pass a callback
easy10 minPass a function to another function and show what it returns.
- 2
A named callback
easy10 minPass a named function to map to double each value, then join with commas.
- 3
A callback with an argument
easy10 minCall the callback three times with the count, collecting the values.
- 4
Filter with a callback
easy10 minUse filter with a callback to keep numbers above 4, then join with commas.
- 5
Transform with a callback
medium10 minWrite a process function that applies a callback to every item. Square them and join with commas.
Find the bug(5)
- 1
Fix the callback called too early
easy8 minThe brackets run the function and pass its result instead.
- 2
Fix the wrong operation
easy8 minThe callback adds 2 instead of doubling.
- 3
Fix the ignored argument
easy8 minThe callback is given the count but never uses it.
- 4
Fix the inverted filter
easy8 minThe condition keeps the wrong numbers.
- 5
Fix the callback that returns nothing
easy8 minWithout 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