Report how many characters the name holds.
Acceptance criteria
- 1.#out should show 12.
JavaScript Tutorial · JavaScript Strings
These 10 tasks go with the JavaScript Strings 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: “A JavaScript string holds text, written inside quotes.” Read the chapter.
1.Count the charactersexercise · easy · 10 min
Report how many characters the name holds.
Passes when: #out should show 12.
2.Read the first characterexercise · easy · 10 min · practice plan
Report the first letter of the text.
Passes when: #out should show h.
3.Read the last characterexercise · easy · 10 min · practice plan
Use at with a negative index to get the last letter.
Passes when: #out should show o.
4.Use both quote stylesexercise · easy · 10 min · practice plan
Build a string containing an apostrophe.
Passes when: #out should show It's fine.
5.Measure trimmed whitespaceexercise · medium · 10 min · practice plan
Report the length of three spaces once trimmed.
Passes when: #out should show 0.
6.Fix length called as a methodbug fix · easy · 8 min
length is a property, so it has no brackets.
Passes when: #out should show 12.
7.Fix the off-by-one last characterbug fix · easy · 8 min · practice plan
The last index is length minus one.
Passes when: #out should show last is o.
8.Fix the unescaped apostrophebug fix · easy · 8 min · practice plan
An apostrophe inside single quotes ends the string early.
Passes when: #out should show It's fine.
9.Fix the character assignmentbug fix · easy · 8 min · practice plan
Strings cannot be changed in place, so build a new one.
Passes when: #out should show Jello.
10.Fix the space counted as emptybug fix · easy · 8 min · practice plan
A single space is a real character.
Passes when: #out should show one character.
Between them these tasks cover Quotes, length and Indexing.
Looking for a different chapter? See every practice set, or switch to the interview theory questions.