Skip to main content

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

    Transform with map

    easy10 min

    Add 20 percent to each price and join the results with commas.

  2. 2

    Keep some with filter

    easy10 min

    Keep only numbers above 4 and join them with commas.

  3. 3

    Total with reduce

    easy10 min

    Add 1, 2, 3 and 4 together using reduce.

  4. 4

    Return a function

    easy10 min

    Write a function that builds a multiplier, then triple 15.

  5. 5

    Chain them together

    medium10 min

    Keep the even numbers from 1 to 6, multiply each by 10, and add them up.

Find the bug(5)

  1. 1

    Fix forEach used instead of map

    easy8 min

    forEach returns nothing, so there is no new array.

  2. 2

    Fix the filter that returns nothing

    easy8 min

    The callback has braces but no return, so nothing is kept.

  3. 3

    Fix the missing starting value

    easy8 min

    Without a starting value the first item is used as the total.

  4. 4

    Fix the function called instead of returned

    easy8 min

    The outer function returns a number, not a function.

  5. 5

    Fix the wrong chain order

    easy8 min

    Multiplying 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