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

Fill in the blank to get the node name. let nameOfNode = selectedNode._______; nodeName nodeName
Fill in the blank to get the node name of the second element of selectedElement. let nameOfNode = __________________; selectedElement.children[1].nodeName; selectedElement\.children\[1\]\.nodeName;
Here is some markup, followed by a JavaScript statement. What will be displayed in the Chrome console? <div>
  <h2>The slow loris</h2>
  <p>Few mammals are slower than the slow loris.</p>
</div>

console.log(document.querySelector("div").children[1].nodeName);
P [P|p]
An element has been assigned to a variable, el. Display the name of its parent in the console. console.log(el.parentNode.nodeName); console\.log\(el\.parentNode\.nodeName\);
What is the node name of a text node, as displayed in the Chrome console? #text #text
Below is the markup. The <p> element has been assigned to a variable, pgraph. Display the node name of the element's child in the console. Remember, the keyword children gives you a collection of element nodes only, so it won't work for getting a node that isn't an element. <p>Hello World!</p> console.log(pgraph.childNodes[0].nodeName); console\.log\(pgraph\.childNodes\[0\]\.nodeName\);
Below is some markup. The list item has been assigned to a variable, item. In a single statement, work your way up the DOM tree to the <div>. Assign its node name to a variable that hasn't been declared beforehand. Make up the name of the variable. <div>
  <ul>
    <li>The only item</li>
  </ul>
</div>
let nName = item.parentNode.parentNode.nodeName; let[a-z_$][a-zA-Z0-9_$]*=item\.parentNode\.parentNode\.nodeName;
Find the name of the first child element of the first child element of an element that has been assigned to the variable el. Assign the name to a variable that hasn't been declared beforehand. Make up the name of the variable. let ch = el.children[0].children[0].nodeName; let[a-z_$][a-zA-Z0-9_$]*=el\.children\[0\]\.children\[0\]\.nodeName;
  1. Click the HTML button to see my markup.
  2. Click the JS button to code.
  3. Working your way down from the <div>, display the node name of the <span> element in an alert using the children keyword.
  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 SPAN.
  7. Dismiss the alert by clicking OK.
  8. For help with this code, see Chapter 112 in the book.
  1. Click the HTML button to see my markup.
  2. Click the JS button to code.
  3. Working your way up from the <span> element, display the node name of the <div> 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 DIV.
  7. Dismiss the alert by clicking OK.
  8. For help with this code, see Chapter 112 in the book.