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

If this is the markup, what value is returned by the getAttribute() method? <img src = "pic1.jpg"> "pic1.jpg" •pic1\.jpg•
If you use getAttribute() and there is no such attribute, the value returned is either "" or ____. null null
The targeted element has been assigned to the variable el. Code the rest of the statement to find the value of the attribute named "target". let valTarget = ______________________________; el.getAttribute("target"); el\.getAttribute\(•target•\);
Code the rest of the statement to find the value of the src attribute of the only image on the page. let valSrc = ____________________________; document.querySelector("img").getAttribute("src"); document\.querySelector\(•img•\)\.getAttribute\(•src•\);
The targeted element has been assigned to the variable el. Find the value of an attribute of the element and assign the value to a variable. Make up the attribute name and the variable name. let valAttribute = el.getAttribute("href"); let[a-z_$][a-zA-Z0-9_$]*=el\.getAttribute\(•.*•\);
In a single statement, find the value of an element's align attribute and assign it to a variable. Target the element by id. Make up the variable name and the id. let valAttribute = document.querySelector("#div-3").getAttribute("align"); let[a-z_$][a-zA-Z0-9_$]*=document\.querySelector\(•#.*•\)\.getAttribute\(•align•\);
An element has been assigned to the variable el. Check whether a particular attribute on el exists and assign the result to a variable. Make up the attribute and the variable name. let itExists = el.hasAttribute("title"); let[a-z_$][a-zA-Z0-9_$]*=el\.hasAttribute\(•.*•\);
An element has been assigned to the variable el. Code an if statement. If a src attribute exists on the element, assign it the name of a jpg image. Make up the attribute value. if (el.hasAttribute("src")) {
  el.setAttribute("src", "images/loris.jpg");
}
if\(el\.hasAttribute\(•src•\)\){[\r\n]el\.setAttribute\(•src•,•.*\.jpg•\);[\r\n]}
  1. Click the HTML button to see an image tag.
  2. Click the Result button to see the image on the page.
  3. Click the JS button. I've assigned an alternate image link to a variable, whiteLink.
  4. Code an if statement. If the value of src is not whiteLink, set the attribute to whiteLink.
  5. If you've coded correctly, the image will be replaced by an image of a white loris.
  6. For help with this code, see Chapter 75 in the book.
  1. Click the HTML button to see two paragraphs that I've coded.
  2. Click the Result button to see the paragraphs.
  3. Click the JS button.
  4. Code an if statement. If the second paragraph (id "p1") has the attribute "title", set the value of its title to a new value.
  5. Display the value of the new title in an alert.
  6. Wait a moment.
  7. If you've coded correctly, an alert will display the value of the new title.
  8. Dismiss the alert by clicking OK.
  9. For help with this code, see Chapter 75 in the book.