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

The alternative to childNodes[0] is _________. firstChild firstChild
The alternative to children[0] is _________. firstElementChild firstElementChild
A div has been assigned to a variable, parent. Assign its last non-whitespace child to the variable lastParagraph. The variable hasn't been declared beforehand. let lastParagraph = parent.lastElementChild; letlastParagraph=parent\.lastElementChild;
A div has been assigned to a variable, parent. An <h2> heading is the first child of the div that isn't whitespace. Display the text content of the heading in the console. console.log(parent.firstElementChild.textContent); console\.log\(parent\.firstElementChild\.textContent\);
In the console, display the node name of the last element node of a div that's been assigned to the variable mainDiv. Do it with a single statement. console.log(mainDiv.lastElementChild.nodeName); console\.log\(mainDiv\.lastElementChild\.nodeName\);
An element has been assigned to the variable el. Code this: If the first child of el is text, display a message in the console. Make up the message. if (el.firstChild.nodeName === "#text") {
  console.log("Text node!");
}
if\(el\.firstChild\.nodeName===•#text•\){[\r\n]console\.log\(•.*•\);
Using what you learned in this chapter, assign the next element sibling of the first child of a parent to a variable. Make up the name of the variable that represents the parent and the variable that represents the sibling. let sib = parentEl.firstElementChild.nextElementSibling; let[a-z_$][a-zA-Z0-9_$]*=[a-z_$][a-zA-Z0-9_$]*\.firstElementChild\.nextElementSibling;
An ordered list has been assigned to the variable parentElement. In the console display the text content of the last element child of parentElement. console.log(parentElement.lastElementChild.textContent); console\.log\(parentElement\.lastElementChild\.textContent\);
  1. Click the HTML button to see my markup.
  2. Click the JS button.
  3. Starting with the div and working your way down the DOM tree, display the winner of the race in an alert. Use firstElementChild where possible.
  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 "Tortoise".
  7. Dismiss the alert by clicking OK.
  8. For help with this code, see Chapter 114 in the book.
  1. Click the HTML button to see my markup.
  2. Click the JS button.
  3. In an alert display the number of child nodes of the div that are elements.
  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 number 3.
  7. Dismiss the alert by clicking OK.
  8. For help with this code, see Chapter 114 in the book.