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
Keep the even numbers
easy10 minFilter a list down to the even numbers and join them with commas.
- 2
Keep the passing scores
easy10 minFilter scores to those of 50 or more and join them with commas.
- 3
Filter objects
easy10 minKeep only the active users and show their names joined by commas.
- 4
Remove empty values
easy10 minUse filter with Boolean to drop the falsy values, then join with commas.
- 5
Filter then map
medium10 minKeep the even numbers, multiply them by 10, and join with commas.
Find the bug(5)
- 1
Fix the missing return in filter
easy8 minWithout a return the callback gives undefined, which is falsy.
- 2
Fix the inverted condition
easy8 minThe wrong half of the list is being kept.
- 3
Fix map used instead of filter
easy8 minmap keeps every element, so the list never shrinks.
- 4
Fix the assignment in the condition
easy8 minA single equals sign assigns instead of comparing.
- 5
Fix the falsy values left in
easy8 minEmpty 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