JavaScript Simplified / Chapter 116 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 assemble a collection of all <p>s in the document, you write document.getElementsByTagName(__) "p" •p•
To assemble a collection of all elements in the document that share the class "special", you write document._______________("special") getElementsByClassName getElementsByClassName
Complete the statement to assemble a list of spans in the document. let allSpans = _____________; document.getElementsByClassName("span") document\.getElementsByClassName\(•span•\)
Complete the statement to assemble a list of all elements in the document that share the class "emphasize". let emElements = ________________; document.getElementsByClassName("emphasize") document\.getElementsByClassName\(•emphasize•\)
A <div> has been assigned to a variable, targetDiv. Get a collection of tables within the <div>. Assign the collection to a variable that hasn't been declared beforehand. Make up the name of the variable. let tableCollection = targetDiv.getElementsByTagName("table"); let[a-z_$][a-zA-Z0-9_$]*=targetDiv\.getElementsByTagName\(•table•\);
A table has been assigned to a variable, tbl. Get a collection of elements within the table that share the class "prominent". Assign the collection to a variable that hasn't been declared beforehand. Make up the name of the variable. let boldEls = tbl.getElementsByClass("prominent"); let[a-z_$][a-zA-Z0-9_$]*=tbl\.getElementsByClass\(•prominent•\);
A collection of anchors has been assigned to a variable, aCollection. Get the href attribute of the second anchor in the collection. Assign it to a variable that hasn't been declared beforehand. Make up the name of the variable. let lnk = aCollection[1].getAttribute("href"); let[a-z_$][a-zA-Z0-9_$]*=aCollection\[1\]\.getAttribute\(•href•\);
A collection of elements that share the same class has been assigned to a variable, normies. Get the node name of the first element in the collection. Display it in the console. console.log(normies[0].nodeName); console\.log\(normies\[0\]\.nodeName\);
  1. Click the HTML button to see my markup.
  2. Click the JS button.
  3. Make a collection of all elements that share the class "normal". In an alert, display the number of elements in the collection.
  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 2.
  7. Dismiss the alert by clicking OK.
  8. For help with this code, see Chapter 116 in the book.
  1. Click the HTML button to see my markup.
  2. Click the JS button.
  3. Make a collection of all the <p> elements within the <div> whose id is "d1". In the console, display the text content of the last <p> in the collection.
  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 "All the town's orthopedists".
  7. Dismiss the alert by clicking OK.
  8. For help with this code, see Chapter 116 in the book.