JavaScript String slice — exercises and bug fixes
5 hands-on exercises and 5 find-the-bug challenges for the JavaScript String slice 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
Take the first word
easy10 minTake the first four characters of JavaScript.
- 2
Take the rest
easy10 minTake everything from position four onwards.
- 3
Take the last three
easy10 minUse a negative index to take the extension.
- 4
Drop the extension
easy10 minTake everything except the last four characters.
- 5
Shorten long text
medium10 minCut the text to six characters and add an ellipsis.
Find the bug(5)
- 1
Fix the end index included
easy8 minThe end index is not part of the result, so it takes one too few.
- 2
Fix substring given a negative
easy8 minsubstring treats a negative as zero, so it returns everything.
- 3
Fix the wrong end trimmed
easy8 minThe extension should go, not the name.
- 4
Fix the missing ellipsis
easy8 minShortened text should show that it was cut.
- 5
Fix charAt given a negative
easy8 mincharAt does not accept negative indexes; at does.
Ready to write the code?
The editor, the automatic checks and the worked solutions open up with an account.
Open the workspace