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

"src" is an element's ______. attribute attribute
The method used to change or add an attribute is ___Attribute(). set set
The target element has been assigned to the variable targ. Fill in the blank to change its attribute. ____________________("name", "mobile"); targ.setAttribute targ\.setAttribute
The target element with an attribute of "src" has been assigned to the variable pic. Change the value of the attribute to "loris.png". pic.setAttribute("src", "loris.png"); pic\.setAttribute\(•src•,•loris\.png•\);
An anchor has been assigned to the variable lnk. Change its web address to "loris.html" lnk.setAttribute("href", "loris.html"); lnk\.setAttribute\.\(•href•,•loris\.html•\);
Target an element by id and assign it to a variable. Make up the id and the name of the variable. let elementToChange = document.querySelector("#first-paragraph"); let[a-z_$][a-zA-Z0-9_$]*=document\.querySelector\(•#.*•\);
A button has been assigned to the variable btn. Code an event listener that executes an arrow function. The arrow function displays an alert when the button is clicked. Make up the alert message. btn.addEventListener("click", () => { alert("You clicked!"); }); btn\.addEventListener\(•click•,\(\)=>{?alert\(•.*•\);}?\);
In a single statement, target the h1 heading and add a "name" attribute. Make up the value of the attribute. document.querySelector("h1").setAttribute("name", "top-heading"); document\.querySelector\(•h1•\)\.setAttribute\(•name•,•.*•\);
  1. Click the HTML button to see my markup for a paragraph and a button.
  2. Click the Result button to see the page rendered by my markup.
  3. Click the JS button.
  4. When the Click to center button is clicked, the "align" attribute of the paragraph is changed to "center". Replace the asterisks with the correct code.
  5. Click the Click to center button.
  6. If you've coded correctly, the paragraph will center.
  7. For help with this code, see Chapter 73 in the book.
  1. Click the HTML button to see my markup for a paragraph and a button.
  2. Click the CSS button to see my CSS.
  3. Click the Result button to see the page rendered by my markup.
  4. Click the JS button. I've assigned the two elements to variables.
  5. When the Change class button is clicked, the "class" attribute of the paragraph is set to "ugly". Code the event listener and set the attribute.
  6. Click the Change class button.
  7. If you've coded correctly, the paragraph will display in green against a yellow background.
  8. For help with this code, see Chapter 73 in the book.