JavaScript String trim — exercises and bug fixes
5 hands-on exercises and 5 find-the-bug challenges for the JavaScript String trim 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
Trim the ends
easy10 minRemove the spaces around the name.
- 2
Detect an empty field
easy10 minReport that a field of spaces is really empty.
- 3
Pad a number
easy10 minAdd a leading zero to the minutes.
- 4
Build a clock time
easy10 minPad both parts to make a proper time.
- 5
Mask a card number
medium10 minShow only the last four digits.
Find the bug(5)
- 1
Fix the untrimmed check
easy8 minA field of spaces is being treated as filled in.
- 2
Fix the trim result discarded
easy8 mintrim returns a new string and does not change the original.
- 3
Fix padEnd used for a leading zero
easy8 minThe zero belongs at the front.
- 4
Fix the number not converted
easy8 minpadStart is a string method, so the number needs converting first.
- 5
Fix the target length too short
easy8 minThe mask needs to reach twelve characters.
Ready to write the code?
The editor, the automatic checks and the worked solutions open up with an account.
Open the workspace