Assign the uppercase version back to the variable.
Acceptance criteria
- 1.#out should show HELLO.
JavaScript Tutorial · JavaScript Strings
These 10 tasks go with the JavaScript String Immutability 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: “Strings cannot be changed; every method returns a new one.” .
1.Keep the resultexercise · easy · 10 min
Assign the uppercase version back to the variable.
Passes when: #out should show HELLO.
2.Show the original survivesexercise · easy · 10 min · practice plan
Call a method without assigning and report the variable.
Passes when: #out should show hello.
3.Change one characterexercise · easy · 10 min · practice plan
Rebuild the string with a capital first letter.
Passes when: #out should show Hello.
4.Chain three methodsexercise · easy · 10 min · practice plan
Trim, lowercase and replace in one chain.
Passes when: #out should show ada-lovelace.
5.Build with an arrayexercise · medium · 10 min · practice plan
Collect the pieces and join them once.
Passes when: #out should show item1, item2, item3.
6.Fix the result never assignedbug fix · easy · 8 min
The method returns a new string that was thrown away.
Passes when: #out should show assigned properly.
7.Fix the character assignmentbug fix · easy · 8 min · practice plan
Assigning to a position is silently ignored.
Passes when: #out should show Jello.
8.Fix the broken chainbug fix · easy · 8 min · practice plan
Each method returns a new string, so the calls must be chained.
Passes when: #out should show ada-lovelace.
9.Fix the push used on a stringbug fix · easy · 8 min · practice plan
Only an array can be pushed to, and join avoids a trailing separator.
Passes when: #out should show clean list.
10.Fix the const reassignment attemptbug fix · easy · 8 min · practice plan
A const cannot be reassigned, so use a new variable.
Passes when: #out should show HELLO.
Between them these tasks cover Immutability, Reassignment and Chaining.
Looking for a different chapter? See every practice set, or switch to the interview theory questions.