Skip to main content

JavaScript Strings — exercises and bug fixes

5 hands-on exercises and 5 find-the-bug challenges for the JavaScript Strings 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

    Count the characters

    easy10 min

    Report how many characters the name holds.

  2. 2

    Read the first character

    easy10 min

    Report the first letter of the text.

  3. 3

    Read the last character

    easy10 min

    Use at with a negative index to get the last letter.

  4. 4

    Use both quote styles

    easy10 min

    Build a string containing an apostrophe.

  5. 5

    Measure trimmed whitespace

    medium10 min

    Report the length of three spaces once trimmed.

Find the bug(5)

  1. 1

    Fix length called as a method

    easy8 min

    length is a property, so it has no brackets.

  2. 2

    Fix the off-by-one last character

    easy8 min

    The last index is length minus one.

  3. 3

    Fix the unescaped apostrophe

    easy8 min

    An apostrophe inside single quotes ends the string early.

  4. 4

    Fix the character assignment

    easy8 min

    Strings cannot be changed in place, so build a new one.

  5. 5

    Fix the space counted as empty

    easy8 min

    A single space is a real character.

Ready to write the code?

The editor, the automatic checks and the worked solutions open up with an account.

Open the workspace