Take the first four characters of JavaScript.
Acceptance criteria
- 1.#out should show Java.
JavaScript Tutorial · JavaScript Strings
These 10 tasks go with the JavaScript String slice 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: “slice takes a piece out of a string without changing the original.” .
1.Take the first wordexercise · easy · 10 min
Take the first four characters of JavaScript.
Passes when: #out should show Java.
2.Take the restexercise · easy · 10 min · practice plan
Take everything from position four onwards.
Passes when: #out should show Script.
3.Take the last threeexercise · easy · 10 min · practice plan
Use a negative index to take the extension.
Passes when: #out should show pdf.
4.Drop the extensionexercise · easy · 10 min · practice plan
Take everything except the last four characters.
Passes when: #out should show report.
5.Shorten long textexercise · medium · 10 min · practice plan
Cut the text to six characters and add an ellipsis.
Passes when: #out should show A very....
6.Fix the end index includedbug fix · easy · 8 min
The end index is not part of the result, so it takes one too few.
Passes when: #out should show Java.
7.Fix substring given a negativebug fix · easy · 8 min · practice plan
substring treats a negative as zero, so it returns everything.
Passes when: #out should show just pdf.
8.Fix the wrong end trimmedbug fix · easy · 8 min · practice plan
The extension should go, not the name.
Passes when: #out should show report.
9.Fix the missing ellipsisbug fix · easy · 8 min · practice plan
Shortened text should show that it was cut.
Passes when: #out should show A very followed by three dots.
10.Fix charAt given a negativebug fix · easy · 8 min · practice plan
charAt does not accept negative indexes; at does.
Passes when: #out should show last is t.
Between them these tasks cover slice, Negative indexes and charAt.
Looking for a different chapter? See every practice set, or switch to the interview theory questions.