JavaScript Higher Order Functions — exercises and bug fixes
5 hands-on exercises and 5 find-the-bug challenges for the JavaScript Higher Order 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
Transform with map
easy10 minAdd 20 percent to each price and join the results with commas.
- 2
Keep some with filter
easy10 minKeep only numbers above 4 and join them with commas.
- 3
Total with reduce
easy10 minAdd 1, 2, 3 and 4 together using reduce.
- 4
Return a function
easy10 minWrite a function that builds a multiplier, then triple 15.
- 5
Chain them together
medium10 minKeep the even numbers from 1 to 6, multiply each by 10, and add them up.
Find the bug(5)
- 1
Fix forEach used instead of map
easy8 minforEach returns nothing, so there is no new array.
- 2
Fix the filter that returns nothing
easy8 minThe callback has braces but no return, so nothing is kept.
- 3
Fix the missing starting value
easy8 minWithout a starting value the first item is used as the total.
- 4
Fix the function called instead of returned
easy8 minThe outer function returns a number, not a function.
- 5
Fix the wrong chain order
easy8 minMultiplying before filtering changes which numbers are kept.
Ready to write the code?
The editor, the automatic checks and the worked solutions open up with an account.
Open the workspace