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

An element has been assigned to the variable el. Fill in the blank to get the text without tags. let textOfEl = el._______; textContent textContent
The markup for a list has been assigned to the variable players. Fill in the blank to copy the list, including formatting, to the targeted element. receivingElement._______ = players; innerHTML innerHTML
Some tags and text have been assigned to the variable content. Assign that content to the element with an id of "p1". document.querySelector("#p1").innerHTML = content; document\.querySelector\(•#p1•\)\.innerHTML=content;
A paragraph has been assigned to the variable graph. Assign the tags and text inside it to the variable tagsAndText, which hasn't been declared beforehand. let tagsAndText = graph.innerHTML; lettagsAndText=graph\.innerHTML;
In a single statement get the text but not tags from the h1 heading and assign it to a variable. Make up the name of the variable. let txt = document.querySelector("h1").textContent; let[a-z_$][a-zA-Z0-9_$]*=document\.querySelector\(•h1•\)\.textContent;
An element has been assigned to a variable. A second element has been assigned to another variable. In a single statement copy the text and formatting of one element to the other. Make up the variable names. ele1.innerHTML = ele2.innerHTML; [a-z_$][a-zA-Z0-9_$]*\.innerHTML=[a-z_$][a-zA-Z0-9_$]*\.innerHTML;
The markup for an element is <p id="p1">No <em>sir</em></p>. What will the following statement display? document.querySelector("#p2").textContent = document.querySelector("#p1").innerHTML; No <em>sir</em> No.em>sir<\/em>
Assign the element with an id of "#div-3" to a variable. Then, using the variable, copy its tags and text to an element that has been assigned to a second variable. Make up the variable names. let aDiv = document.querySelector("#div-3");
anotherDiv.innerHTML = aDiv.innerHTML;
let([a-z_$][a-zA-Z0-9_$]*)=document\.querySelector\(•#div-3•\);[\r\n][a-z_$][a-zA-Z0-9_$]*\.innerHTML=\1\.innerHTML;
  1. When the button is clicked, the content and formatting of the paragraph whose ID is "p1", is copied into the paragraph whose ID is "p2".
  2. Click the HTML button to see my HTML markup.
  3. Click the Result button to see the page rendered by the markup in the Result panel.
  4. Click the JS button.
  5. Code the body of the function.
  6. Click the Copy text and formatting button in the Result panel.
  7. If you've coded correctly, the second paragraph will have the same text and formatting as the first paragraph.
  8. For help with this code, see Chapter 70 in the book.
  1. I've coded markup for a paragraph and a button. Click the HTML button to see it.
  2. Click the Result button to see the page rendered by my markup in the Result panel. There's a button but no text because I coded an empty paragraph.
  3. Click the JS button. I've assigned the button and the paragraph to variables.
  4. Code an event listener that watches for the button to be clicked.
  5. When the button is clicked, an anonymous function runs.
  6. The anonymous function checks to see whether the textContent of the paragraph is "" (empty). If so, it inserts some textContent into the paragraph. Make up the text.
  7. Click the Click me button.
  8. If you've coded correctly, your text will display in the Result panel.
  9. For help with this code, see Chapter 70 in the book.