JavaScript Array find — exercises and bug fixes
5 hands-on exercises and 5 find-the-bug challenges for the JavaScript Array find 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
Find the first match
easy10 minShow the first number in the list that is above four.
- 2
Find an object by id
easy10 minFind the user with id 2 and show their name.
- 3
Report no match
easy10 minShow the type of what find gives back when nothing matches.
- 4
Find a position
easy10 minUse findIndex to show where the letter b sits.
- 5
Find the last match
medium10 minUse findLast to show the last number above four.
Find the bug(5)
- 1
Fix filter used instead of find
easy8 minfilter gives an array, but a single value is wanted.
- 2
Fix the guard checking for null
easy8 minfind returns undefined when nothing matches, not null, so the guard never fires.
- 3
Fix find used for a position
easy8 minThe index is wanted, not the value itself.
- 4
Fix the loose id comparison
easy8 minThe wrong user is found because the condition compares the wrong property.
- 5
Fix first used instead of last
easy8 minThe last match is wanted, not the first.
Ready to write the code?
The editor, the automatic checks and the worked solutions open up with an account.
Open the workspace