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

To target element nodes, you use the keyword _______. children children
The keyword children is used to create a collection of _______ (one word). elements elements
A parent element has been assigned to the variable parentElement. Assign the first child of parentElement to a variable, child1. The variable hasn't been declared beforehand. let child1 = parentElement.children[0]; letchild1=parentElement\.children\[0\];
An element has been assigned to a variable, el. Assign the element's 8th child to another variable that hasn't been declared beforehand. Make up the name of the variable. let child8 = el.children[7]; let[a-z_$][a-zA-Z0-9_$]*=el\.children\[7\];
In a first statement, assign the only ul on the page to a variable. In a second statement, assign the third child of the ul to another variable. Neither variable has been declared beforehand. Make up the names of the variables. let list = document.querySelector("ul");
let thirdItem = list.children[2];
let([a-z_$][a-zA-Z0-9_$]*)=document\.querySelector\(•ul•\);[\r\n]let[a-z_$][a-zA-Z0-9_$]*=\1\.children\[2\];
In a single statement, assign the sixth child of the only table on the page to a variable that hasn't been declared beforehand. Make up the name of the variable. let el = document.querySelector("table").children[5]; let[a-z_$][a-zA-Z0-9_$]*=document\.querySelector\(•table•\)\.children\[5\];
In a first statement, assign to the variable target the third paragraph of a div whose ID is "intro". In a second statement, assign the textContent of the paragraph to the variable txt. Neither variable has been declared beforehand. let target = document.querySelector("#intro").children[2];
let txt = target.textContent;
lettarget=document\.querySelector\(•#intro•\)\.children\[2\];[\r\n]lettxt=target\.textContent;
In a first statement, assign the first paragraph of a div to a variable, which hasn't been declared beforehand. In a second statement, set the textContent of the paragraph to a string. Make up the ID of the div, the name of the variable, and the string. let target = document.querySelector("#humpty").children[0];
target.textContent = "Hello World!";
let([a-z_$][a-zA-Z0-9_$]*)=document\.querySelector\(•#.*•\)\.children\[0\];[\r\n]\1\.textContent=•.*•;
  1. Click the HTML button to see my markup.
  2. Click the JS button.
  3. Assign the div to a variable.
  4. Using the variable and the keyword children, display the text of the second paragraph in an alert.
  5. Click the Result button (or, after revising, don't click, just wait).
  6. If you've coded correctly, an alert will display "Northern Cal is rainy."
  7. Dismiss the alert by clicking OK.
  8. For help with this code, see Chapter 111 in the book.
  1. Click the HTML button to see my markup.
  2. Click the JS button.
  3. Assign the div to a variable.
  4. Using the variable and the keyword children, set the third paragraph's text to a new string.
  5. Click the Result button (or, after revising, don't click, just wait).
  6. Wait a moment.
  7. If you've coded correctly, the text of the third paragraph will change to your string.
  8. Dismiss the alert by clicking OK.
  9. For help with this code, see Chapter 111 in the book.