JavaScript Simplified / Chapter 115 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 three types of nodes I've covered in the book are elements, text, and _____. comments comments
An attribute is a ______ of a node. property property
An image has been assigned to a variable, pic. Assign the value of its source to a variable, picSource, which hasn't been declared beforehand. let picSource = pic.getAttribute("src"); letpicSource=pic\.getAttribute\(•src•\);
A paragraph has been assigned to a variable, pgraph. Assign the value of its class or classes to a variable, classes, that hasn't been declared beforehand. let classes = pgraph.getAttribute("class"); letclasses=pgraph\.getAttribute\(•class•\);
A div has been assigned to a variable, parentEl. This element is followed by whitespace, then a comment. In the console, display the node name of the comment. console.log(parentEl.childNodes[1].nodeName); console\.log\(parentEl\.childNodes\[1\]\.nodeName\);
A form has been assigned to a variable, frm. Display the value of its id attribute in the console. console.log(frm.getAttribute("id")); console\.log\(frm\.getAttribute\(•id•\)\);
A paragraph has been assigned to a variable, pgraph. Delete its class attribute. pgraph.removeAttribute("class"); pgraph\.removeAttribute\(•class•\);
An element has been assigned to a variable, el. If the element's third element child is an <h4> element, display the <h4>'s class or classes in the console. Do it in three lines of code. Use the children keyword. if (el.children[2].nodeName === "h4") {
  console.log(el.children[2].getAttribute("class"));
}
if\(el\.children\[2\]\.nodeName===•h4•\){[\r\n]console\.log\(el\.children\[2\]\.getAttribute\(•class•\)\);[\r\n]}
  1. Click the HTML button to see my markup.
  2. Click the JS button.
  3. Starting with the paragraph, navigate the DOM tree to display the text content of the comment 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 "This may change"
  7. Dismiss the alert by clicking OK.
  8. For help with this code, see Chapter 115 in the book.
  1. Click the HTML button to see my markup.
  2. Click the JS button.
  3. Starting with one of the paragraphs, work your way up the DOM tree to display the value of the div's classes 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 "special centered".
  7. Dismiss the alert by clicking OK.
  8. For help with this code, see Chapter 115 in the book.