Quizz
The full text of this chapter, to read or revisit. To practise, do the exercises.
βΆ Do the exercisesExercise 1 β Quiz: The First Letters
What does this code print?
console.log("Aquachu".slice(0, 4));AquaAquacquacchuHint : The end index marks where to stop, without joining.
Exercise 2 β Quiz: To the End
What does this code print?
console.log("Aquachu".slice(4));chuAquaachuAquachuHint : With one argument, the cut runs to the last character.
Exercise 3 β Quiz: From the End
What does this code print?
console.log("Metachu".slice(-3));chuMetMetaachuHint : A negative number counts backwards.
Exercise 4 β Quiz: Original Untouched
What does this code print?
const name = "Zapchu";
name.slice(0, 3);
console.log(name);ZapchuZap""Hint : A string can never be modified in place.
Exercise 5 β Quiz: Cut Three Letters
Keep the first three characters.
Hint : One method cuts a piece, and the end index is excluded.
Exercise 6 β Quiz: substring and Negatives
What does this code print?
console.log("Zapchu".substring(-3));ZapchuchuZap""Hint : One of the two cutting methods refuses negative numbers.
Exercise 7 β Quiz: Only the First
What does this code print?
console.log("a-a-a".replace("a", "b"));b-a-ab-b-ba-a-abHint : This method stops after one match.
Exercise 8 β Quiz: All of Them
What does this code print?
console.log("a-a-a".replaceAll("a", "b"));b-b-bb-a-aa-a-abbbHint : This one keeps going to the end of the text.
Exercise 9 β Quiz: Replaced by Nothing
What does this code print?
console.log("Z-a-p".replaceAll("-", ""));ZapZ-a-pZa-p""Hint : Replacing with an empty string removes what was found.
Exercise 10 β Quiz: Fill the Template
Put `"Zap"` in place of `NAME`.
Hint : One method swaps a piece of text, and text needs quotes.
Exercise 11 β Quiz: Padded Left
What does this code print?
console.log("7".padStart(3, "0"));0077007000Hint : The method name says which side receives the filler.
Exercise 12 β Quiz: Padded Right
What does this code print?
console.log("7".padEnd(3, "0"));7000077000Hint : The other side this time.
Exercise 13 β Quiz: Too Long Already
What does this code print?
console.log("Aquachu".padStart(4, "*"));AquachuAqua***Aquachu*AquachuHint : Padding can only make text longer.
Exercise 14 β Quiz: Padding a Number
`level` is the number `7`. Which line prints `007`?
String(level).padStart(3, "0")level.padStart(3, "0")level.padEnd(3, "0")String(level).padEnd(3, "0")Hint : Padding belongs to strings, and the filler goes on the side numbers are read from.
Exercise 15 β Quiz: Three Digits
Display the score on three digits, filled with zeros.
Hint : Numbers are read from the right, and the filler is written as text.
Exercise 16 β Quiz: Repeated
What does this code print?
console.log("ab".repeat(3));ababababababababaaabbbHint : The whole piece is repeated, in order.
Exercise 17 β Quiz: Repeated Zero Times
What does this code print?
console.log("x".repeat(0).length);01undefinedHint : Repeating nothing gives an empty result, not an error.
Exercise 18 β Quiz: Length After repeat
What does this code print?
console.log("abc".repeat(2).length);6325Hint : Multiply the length of the piece by the number of times.
Exercise 19 β Quiz: Draw a Line
Print a line of 10 dashes.
Hint : One method multiplies a piece of text the number of times you give it.
Exercise 20 β Quiz: Starts With?
What does this code print?
console.log("LOG: done".startsWith("LOG:"));truefalseLOG:0Hint : Look at the first characters of the text.
Exercise 21 β Quiz: Ends With?
What does this code print?
console.log("Aquachu".endsWith("chu"));truefalsechu3Hint : Look at the last characters of the text.
Exercise 22 β Quiz: Wrong Case
What does this code print?
console.log("Zapchu".startsWith("zap"));falsetrueZapHint : The comparison is exact, letter by letter.
Exercise 23 β Quiz: Family Filter
Keep only the names ending with `"chu"`.
Hint : One method looks at the end, and the piece searched for is text.
Exercise 24 β Quiz: Chained Methods
What does this code print?
console.log("Aquachu".slice(0, 3).toUpperCase());AQUAquAQUACHUaquHint : Each step works on the result of the one before it.
Exercise 25 β Quiz: Which Method?
You want every level number shown on 3 digits, like `042`. Which method?
padStartpadEndrepeatsliceHint : Digits are read from the right, so the filler goes on the left.