JavaScript Array Search — exercises and bug fixes
5 hands-on exercises and 5 find-the-bug challenges for the JavaScript Array Search 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 a position
easy10 minShow the index of Banana in a list of fruit.
- 2
Check for a missing value
easy10 minUse includes to check for a fruit that is not in the list.
- 3
Report a missing index
easy10 minShow the value indexOf gives back when nothing matches.
- 4
Find the last match
easy10 minShow the index of the last time a value appears.
- 5
Search from a position
medium10 minFind the next match after index 0 in a list with two matches.
Find the bug(5)
- 1
Fix the truthy index check
easy8 minAn index of 0 is falsy, so a match at the front is reported as missing.
- 2
Fix the wrong missing value
easy8 minindexOf returns -1 when nothing matches, not undefined.
- 3
Fix the type mismatch
easy8 minThe list holds numbers, but a string is being searched for.
- 4
Fix first used instead of last
easy8 minThe last matching position is wanted, not the first.
- 5
Fix the object compared by value
easy8 minTwo objects that look alike are still different objects.
Ready to write the code?
The editor, the automatic checks and the worked solutions open up with an account.
Open the workspace