Skip to main content

JavaScript Array filter — exercises and bug fixes

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

    Keep the even numbers

    easy10 min

    Filter a list down to the even numbers and join them with commas.

  2. 2

    Keep the passing scores

    easy10 min

    Filter scores to those of 50 or more and join them with commas.

  3. 3

    Filter objects

    easy10 min

    Keep only the active users and show their names joined by commas.

  4. 4

    Remove empty values

    easy10 min

    Use filter with Boolean to drop the falsy values, then join with commas.

  5. 5

    Filter then map

    medium10 min

    Keep the even numbers, multiply them by 10, and join with commas.

Find the bug(5)

  1. 1

    Fix the missing return in filter

    easy8 min

    Without a return the callback gives undefined, which is falsy.

  2. 2

    Fix the inverted condition

    easy8 min

    The wrong half of the list is being kept.

  3. 3

    Fix map used instead of filter

    easy8 min

    map keeps every element, so the list never shrinks.

  4. 4

    Fix the assignment in the condition

    easy8 min

    A single equals sign assigns instead of comparing.

  5. 5

    Fix the falsy values left in

    easy8 min

    Empty strings and nulls should be removed from the list.

Ready to write the code?

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

Open the workspace