JavaScript String Search — exercises and bug fixes
5 hands-on exercises and 5 find-the-bug challenges for the JavaScript String 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
Check for a word
easy10 minReport whether the text contains Script.
- 2
Find a position
easy10 minReport where the word Basics starts.
- 3
Check the ending
easy10 minReport whether the file name ends with pdf.
- 4
Report a missing word
easy10 minReport the value indexOf gives when nothing matches.
- 5
Find the last separator
medium10 minReport the position of the final slash.
Find the bug(5)
- 1
Fix the truthy index check
easy8 minA match at position 0 is falsy, so it looks missing.
- 2
Fix the case-sensitive search
easy8 minThe word is there but capitalised differently.
- 3
Fix first used instead of last
easy8 minThe final slash is wanted, not the first.
- 4
Fix endsWith checking the start
easy8 minThe extension is at the end of the name.
- 5
Fix the search started too late
easy8 minStarting past the match misses it entirely.
Ready to write the code?
The editor, the automatic checks and the worked solutions open up with an account.
Open the workspace