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

Siblings are nodes that share the same ______. parent parent
If your markup is minified so you don't have to worry about irrelevant whitespace, you can use ______ to find the next sibling. nextSibling nextSibling
An image has been assigned to a variable, pic. The markup hasn't been minified. Target the previous element sibling of pic. Assign it to a variable that hasn't been declared beforehand. Make up the name of the variable. let sib = pic.previousElementSibling; let[a-z_$][a-zA-Z0-9_$]*=pic\.previousElementSibling;
An element has been assigned to a variable, pgraph. Code a ridiculously circular statement. Use previousSibling and nextSibling to display the text content of pgraph in the console. Use chaining. console.log(pgraph.previousSibling.nextSibling.textContent); console\.log\(pgraph\.previousSibling\.nextSibling\.textContent\);
An element has been assigned to a variable, e. The markup hasn't been minified. Display the text content of the second sibling of e using nextElementSibling. Use chaining. console.log(e.nextElementSibling.nextElementSibling.textContent); console\.log\(e\.nextElementSibling\.nextElementSibling\.textContent\);
An element has been assigned to a variable, e. In the console, display the node name of the first child element of the next element sibling. console.log(e.nextElementSibling.children[0].nodeName); console\.log\(e\.nextElementSibling\.children\[0\]\.nodeName\);
An element has been assigned to a variable, el. Code the first line of an if statement checking whether the element has a previous sibling of any type. if (el.previousSibling) { if\(el\.previousSibling\){
An element has been assigned to a variable, el. In the console display the node name of the next element sibling of el's second element child. console.log(el.children[1].nextElementSibling.nodeName); console\.log\(el\.children\[1\]\.nextElementSibling\.nodeName\);
  1. Click the HTML button to see my markup.
  2. Click the JS button to code.
  3. Work your way down the tree by targeting the <div>'s second element child and then that element's next sibling. Display the text content of the sibling 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 "Maybe".
  7. Dismiss the alert by clicking OK.
  8. For help with this code, see Chapter 113 in the book.
  • Click the Result button (or, after revising, don't click, just wait).
  • Click the JS button to see my code and to add your code.
  • Below my statement, code a single statement that works its way up the tree from the starting point to display "Truth" in an alert.
  • Wait a moment.
  • If you've coded correctly, an alert will display "Love".
  • Dismiss the alert by clicking OK.
  • For help with this code, see Chapter 113 in the book.