Split the list and report how many parts there are.
Acceptance criteria
- 1.#out should show 3.
JavaScript Tutorial · JavaScript Strings
These 10 tasks go with the JavaScript String split 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: “split turns a string into an array by cutting it at a separator.” .
1.Split on a commaexercise · easy · 10 min
Split the list and report how many parts there are.
Passes when: #out should show 3.
2.Split into wordsexercise · easy · 10 min · practice plan
Report the last word of the sentence.
Passes when: #out should show fox.
3.Reverse the lettersexercise · easy · 10 min · practice plan
Split into characters, reverse them, and join back.
Passes when: #out should show olleh.
4.Join with a separatorexercise · easy · 10 min · practice plan
Join the parts with dashes.
Passes when: #out should show a-b-c.
5.Capitalise every wordexercise · medium · 10 min · practice plan
Split, capitalise each word, then join back.
Passes when: #out should show The Quick Brown Fox.
6.Fix the missing separatorbug fix · easy · 8 min
Splitting with no separator gives one whole piece.
Passes when: #out should show 3.
7.Fix the wrong separatorbug fix · easy · 8 min · practice plan
The sentence is split on words, not commas.
Passes when: #out should show 4.
8.Fix the join that adds commasbug fix · easy · 8 min · practice plan
The letters should be glued together with nothing between.
Passes when: #out should show olleh.
9.Fix the array never joinedbug fix · easy · 8 min · practice plan
The result is still an array of words.
Passes when: #out should show The Quick Brown Fox.
10.Fix reverse used on the stringbug fix · easy · 8 min · practice plan
Only an array can be reversed, so split first.
Passes when: #out should show olleh.
Between them these tasks cover split, join and Text to array.
Looking for a different chapter? See every practice set, or switch to the interview theory questions.