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
Count the characters
easy10 minReport how many characters the name holds.
- 2
Read the first character
easy10 minReport the first letter of the text.
- 3
Read the last character
easy10 minUse at with a negative index to get the last letter.
- 4
Use both quote styles
easy10 minBuild a string containing an apostrophe.
- 5
Measure trimmed whitespace
medium10 minReport the length of three spaces once trimmed.
Find the bug(5)
- 1
Fix length called as a method
easy8 minlength is a property, so it has no brackets.
- 2
Fix the off-by-one last character
easy8 minThe last index is length minus one.
- 3
Fix the unescaped apostrophe
easy8 minAn apostrophe inside single quotes ends the string early.
- 4
Fix the character assignment
easy8 minStrings cannot be changed in place, so build a new one.
- 5
Fix the space counted as empty
easy8 minA 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