JavaScript Simplified / Chapter 35 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 finding the index of "h" in the first instance of "house"? indexOf indexOf
What is the keyword for finding the index of "B" in the last instance of "Bill"? lastIndexOf lastIndexOf
A string has been assigned to the variable str. Find the starting index of the first instance of "go" within the string. Assign the index number to the variable indx, which hasn't been declared beforehand. let indx = str.indexOf("go"); letindx=str\.indexOf\(•go•\);
A string has been assigned to the variable str. You're looking for the starting index of the last instance of a string segment assigned to the variable seg. Assign the index number to the variable indx, which hasn't been declared beforehand. let indx = str.lastIndexOf(seg); letindx=str\.lastIndexOf\(seg\);
A string has been assigned to the variable str. Find the starting index of the first instance of a segment inside the string. Assign the index number to another variable that hasn't been declared beforehand. Make up that variable name and the string you're looking for. let segIndex = str.indexOf("xyz"); let[a-z_$][a-zA-Z0-9_$]*=str\.indexOf\(•.*•\);
A string has been assigned to the variable str. Find the starting index of the last instance of a segment inside the string. Assign the index number to another variable that hasn't been declared beforehand. Make up the name of that variable and the string you're looking for. let segIndex = str.lastIndexOf("xyz"); let[a-z_$][a-zA-Z0-9_$]*=str\.lastIndexOf\(•.*•\);
Code the first line of an if statement that tests whether the segment "xyz" is found in aString. if (aString.indexOf("xyz") !== -1) { if\(aString\.indexOf\(•xyz•\)!==-1\){
A string has been assigned to a variable. A segment you're looking for has been assigned to a second variable. Code an alert that displays the starting index of the first instance of the segment. Make up the variable names. alert(paragraph.indexOf(segment)); alert\([a-z_$][a-zA-Z0-9_$]*\.indexOf\([a-z_$][a-zA-Z0-9_$]*\)\);
  1. Assign a string to a variable.
  2. Code an alert that displays the starting index of a segment that occurs in the string.
  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 index.
  6. Dismiss the alert by clicking OK.
  7. For help with this code, see Chapter 35 in the book.
  1. Assign a string to a variable.
  2. Code an alert that displays the starting index (-1) of a segment that doesn't occur in the string.
  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 -1.
  6. Dismiss the alert by clicking OK.
  7. For help with this code, see Chapter 35 in the book.