Skip to main content

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. 1

    Check for a word

    easy10 min

    Report whether the text contains Script.

  2. 2

    Find a position

    easy10 min

    Report where the word Basics starts.

  3. 3

    Check the ending

    easy10 min

    Report whether the file name ends with pdf.

  4. 4

    Report a missing word

    easy10 min

    Report the value indexOf gives when nothing matches.

  5. 5

    Find the last separator

    medium10 min

    Report the position of the final slash.

Find the bug(5)

  1. 1

    Fix the truthy index check

    easy8 min

    A match at position 0 is falsy, so it looks missing.

  2. 2

    Fix the case-sensitive search

    easy8 min

    The word is there but capitalised differently.

  3. 3

    Fix first used instead of last

    easy8 min

    The final slash is wanted, not the first.

  4. 4

    Fix endsWith checking the start

    easy8 min

    The extension is at the end of the name.

  5. 5

    Fix the search started too late

    easy8 min

    Starting 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