JavaScript String Immutability — exercises and bug fixes
5 hands-on exercises and 5 find-the-bug challenges for the JavaScript String Immutability 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
Keep the result
easy10 minAssign the uppercase version back to the variable.
- 2
Show the original survives
easy10 minCall a method without assigning and report the variable.
- 3
Change one character
easy10 minRebuild the string with a capital first letter.
- 4
Chain three methods
easy10 minTrim, lowercase and replace in one chain.
- 5
Build with an array
medium10 minCollect the pieces and join them once.
Find the bug(5)
- 1
Fix the result never assigned
easy8 minThe method returns a new string that was thrown away.
- 2
Fix the character assignment
easy8 minAssigning to a position is silently ignored.
- 3
Fix the broken chain
easy8 minEach method returns a new string, so the calls must be chained.
- 4
Fix the push used on a string
easy8 minOnly an array can be pushed to, and join avoids a trailing separator.
- 5
Fix the const reassignment attempt
easy8 minA const cannot be reassigned, so use a new variable.
Ready to write the code?
The editor, the automatic checks and the worked solutions open up with an account.
Open the workspace