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

Fill in the blank to add the class if it's absent and remove the class if it's present. pgraph.classList________("hidden"); .toggle \.toggle
Fill in the blank to check whether the element has the class "main". pgraph.___________________________; classList.contains("main"); classList\.contains\(•main•\);
Fill in the blank to replace the class "special" with the class "normal". pgraph.____________________________; classList.replace("special", "normal"); classList\.replace\(•special•,•normal•\);
An element has been assigned to the variable elem. Add a class. Make up the class name. elem.classList.toggle("hidden"); elem\.classList\.toggle\(•.*•\);
An element has been assigned to the variable elem. If it has a particular class, display "Yes" in an alert. Make up the name of the class. if (elem.classList.contains("special")) {
  alert("Yes");
}
if\(elem\.classList\.contains\(•.*•\)\){[\r\n]alert\(•Yes•\);[\r\n]}
An element has been assigned to the variable elem. Replace one class with another. Make up the names of the classes. elem.classList.replace("normal", "special"); elem\.classList\.replace\(•.*•,•.*•\);
An alternative to classList is ______. className className
An element has been assigned to the variable pgraph. Replace all of its classes with another class. Make up the name of the class. Hint: Don't try to do this with classList. pgraph.className = "main"; pgraph\.className=•.*•;
  1. Click the CSS button to see a class ".hidden" that prevents an element from being displayed.
  2. Click the HTML button to see a paragraph with the class "hidden" and a button.
  3. Click the Result button to see the rendered HTML.
  4. Click the JS button.
  5. Add the function that's called in the last statement. It toggles the class when the last statement executes.
  6. Click the Toggle button.
  7. If you've coded correctly, the paragraph will become visible.
  8. For help with this code, see Chapter 72 in the book.
  1. Click the HTML button to see my markup.
  2. Click the CSS button to see a class.
  3. Click the Result button to see the HTML rendered.
  4. Click the JS button.
  5. Complete the function that's called in the last statement. The function checks to see whether the paragraph has the class "greatBig". If not, the function adds it. (There are several correct ways to code this. Take your pick.)
  6. Click the Add class button
  7. If you've coded correctly, the paragraph text will get bigger.
  8. For help with this code, see Chapter 72 in the book.