JavaScript Simplified / Chapter 37 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

When the revised string is assigned to a new variable in the following code, what is the value of x, the original variable? Include quotation marks. let x = "abc";
let y = x.replace("a", "z");
"abc" - When the revised string is assigned to a new variable, the original string is preserved in the original variable. •?abc•?
After these two statements execute, what is the value of x? Include quotation marks. let x = "abc abc";
x = x.replace("a", "z");
"zbc abc" - The statement replaces only the first instance of "a". The revised string is assigned to the original variable, x. •?zbcabc•?
In the string represented by the variable reply, replace the first instance of "no" with "yes" and assign the revised string to revisedReply, which hasn't been declared beforehand. let revisedReply = reply.replace("no", "yes"); letrevisedReply=reply\.replace\(•no•,•yes•\);
In the string represented by the variable reply, replace all instances of "no" with "yes". Assign the revised string to the original variable. reply = reply.replace(/no/g, "yes"); reply=reply\.replace\(\/no\/g,•yes•\);
In the string represented by the variable reply, replace all instances of "one" with "1". Assign the revised string to newStr, which hasn't been declared beforehand. let newStr = reply.replace(/one/g, "1"); letnewStr=reply\.replace\(\/one\/g,•1•\);
In the string represented by a variable, replace the first instance of one string segment with another. Assign the revised string to the original variable. Make up everything. str = str.replace("hee", "haw"); ([a-z_$][a-zA-Z0-9_$]*)=\1\.replace\(•.*•,•.*•\);
In the string represented by a variable, replace all instances of one string with another. Assign the revised string to the original variable. Make up everything. str = str.replace(/hee/g, "haw"); ([a-z_$][a-zA-Z0-9_$]*)=\1\.replace\(\/.*\/g,•.*•\);
The string "Move up" has been assigned to the variable instruction. In a single statement and with the minimum amount of code, code an alert that displays instruction's string, but revised so it says "Move down" alert(instruction.replace("up", "down")); alert\(instruction\.replace\(•up•,•down•\)\);
  1. Assign a string to a variable.
  2. Using the replace keyword, replace a set of characters in it once.
  3. Display an alert, enclosing the variable in the parentheses.
  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 the string with the new set of characters.
  7. Dismiss the alert by clicking OK.
  8. For help with this code, see Chapter 37 in the book.
  1. Assign "To be or not to be" to a variable.
  2. Replace all instances of "be" with "party".
  3. Display an alert, enclosing the variable in the parentheses.
  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 "To party or not to party".
  7. Dismiss the alert by clicking OK.
  8. For help with this code, see Chapter 37 in the book.