JavaScript Simplified / Chapter 33 Exercises

  • Index of exercises
  • Email me

1

2

3

4

5

6

7

8

9

10

Congratulations. You've aced all the exercises for this chapter.


To practice on your own, or to check code you believe shouldn't have been scored as incorrect, go to CodePen.


Are you ready to rate JavaScript Simplified? on Amazon?


Rate it on Amazon.

0,1,2,3,4,5,6,7,8,9

0

0

0

0

What is the keyword for copying a multi-character segment from a string? slice slice
"scoop" has been assigned to someWord. Copy "oop" out of it,using concise code. Fill in the blank. let segment = someWord.slice(___); 2 2
Fill in the blank to assign the first character of originalString to firstChar. Don't use slice(). let firstChar = originalString___; [0] \[0\]
Using slice(), change the value of parent from "mother" to "moth". parent = parent.slice(0, 4); parent=parent\.slice\(0,4\);
Without using slice, display the fifth character in the variable itemNo in an alert. Do it with a single statement. Make up the name of the variable. alert(itemNo[4]); alert\([a-z_$][a-zA-Z0-9_$]*\[4\]\);
The string "elephant" has been assigned to the variable animal. Copy the four middle characters in the string and assign the copied characters to the variable seg, which hasn't been declared beforehand. let seg = animal.slice(2, 6); letseg=animal\.slice\(2,6\);
Assign the second through last characters of a variable to a second variable that hasn't been declared beforehand. Make up the variable names. Use concise coding. let seg = name.slice(1); let[a-z_$][a-zA-Z0-9_$]*=[a-z_$][a-zA-Z0-9_$]*\.slice\(1\);
Given the statement below...
  1. Capitalize the first character and convert the rest of the name to lowercase.
  2. Target the first character by index and the rest of the characters by slice().
  3. Assign the corrected name to the same variable.
  4. Do it all in one statement using concise code.
let firstName = "gErT"; firstName = firstName[0].toUpperCase() + firstName.slice(1).toLowerCase(); firstName=firstName\[0\]\.toUpperCase\(\)\+firstName\.slice\(1\)\.toLowerCase\(\);
  1. Assign a 7-character string to a variable.
  2. Display the 3 middle characters.
  3. Click the Result button (or, after revising, don't click, just wait).
  4. Wait a moment.
  5. If you've coded correctly, an alert will display the 3 middle characters.
  6. Dismiss the alert by clicking OK.
  7. For help with this code, see Chapter 33 in the book.
  1. Assign your first name to one variable, and your last name to another variable.
  2. Using slice, copy your initials to a third variable.
  3. Display the initials in an alert.
  4. Click the Result button (or, after revising, don't click, just wait).
  5. Wait a moment.
  6. If you've coded correctly, an alert will display your initials.
  7. Dismiss the alert by clicking OK.
  8. For help with this code, see Chapter 33 in the book.