Remove the spaces around the name.
Acceptance criteria
- 1.#out should show Ada.
JavaScript Tutorial · JavaScript Strings
These 10 tasks go with the JavaScript String trim chapter. 5 of them ask you to build something small from scratch; 5 give you code that is already broken and ask you to work out why. Set aside about 90 minutes for the whole set, though you can do them in any order.
Nothing here is marked by a person. When you press Submit, the editor checks your code against the points listed under each task and tells you straight away what passed and what didn't (you need a free account to submit). If you get stuck, there are hints, and a worked solution once you've had a go. The first 2 tasks are free; the rest are part of the practice plan.
If it's been a while since you read the chapter, here is how it starts: “trim removes whitespace from both ends of a string.” .
1.Trim the endsexercise · easy · 10 min
Remove the spaces around the name.
Passes when: #out should show Ada.
2.Detect an empty fieldexercise · easy · 10 min · practice plan
Report that a field of spaces is really empty.
Passes when: #out should show empty field.
3.Pad a numberexercise · easy · 10 min · practice plan
Add a leading zero to the minutes.
Passes when: #out should show 05.
4.Build a clock timeexercise · easy · 10 min · practice plan
Pad both parts to make a proper time.
Passes when: #out should show 09:05.
5.Mask a card numberexercise · medium · 10 min · practice plan
Show only the last four digits.
Passes when: #out should show ********4242.
6.Fix the untrimmed checkbug fix · easy · 8 min
A field of spaces is being treated as filled in.
Passes when: #out should show empty field.
7.Fix the trim result discardedbug fix · easy · 8 min · practice plan
trim returns a new string and does not change the original.
Passes when: #out should show length 3.
8.Fix padEnd used for a leading zerobug fix · easy · 8 min · practice plan
The zero belongs at the front.
Passes when: #out should show 05.
9.Fix the number not convertedbug fix · easy · 8 min · practice plan
padStart is a string method, so the number needs converting first.
Passes when: #out should show 09.
10.Fix the target length too shortbug fix · easy · 8 min · practice plan
The mask needs to reach twelve characters.
Passes when: #out should show eight stars then 4242.
Between them these tasks cover trim, padStart and Input cleaning.
Looking for a different chapter? See every practice set, or switch to the interview theory questions.