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

A callback is a named, anonymous, or arrow function passed as an ______ to another function. argument argument
In the following code, what is the name of the callback? calcTotal(5, 31, displayTotal); displayTotal displayTotal
Fill in the blank. The first line of the callback function is...
function payCompliment() {
document.querySelector("button").addEventListener("click",________); payCompliment payCompliment
Code the first line of a function that has a named callback as the argument. Make up the names. function calc(anotherFunc) { function[a-z_$][a-zA-Z0-9_$]*\([a-z_$][a-zA-Z0-9_$]*\){
Fill in the blanks with an anonymous function as the callback. The callback displays an alert. Make up the alert text. setTimeout(________
  ______________
_, 2000);
function() {
  alert("2 seconds have passed");
}
function\(\){[\r\n]alert\(•.*•\);[\r\n]}
Code a setTimeout() statement. The callback is an arrow function without brackets that displays an alert after 5 seconds. Make up the alert text. setTimeout(() => alert("Hello"), 5000); setTimeout\(\(\)=>{?alert\(•.*•\)}?,5000\);
Rewrite the addEventListener() statement below, substituting an anonymous function as the callback. function sayHi() {
  alert("Hi");
}
document.querySelector("button").addEventListener("click", sayHi);
document.querySelector("button").addEventListener("click", function() {
  alert("Hi");
});
document\.querySelector\(•button•\)\.addEventListener\(•click•,function\(\){[\r\n]?alert\(•Hi•\);[\r\n]?}\);
A button has been assigned to the variable btn. A paragraph has been assigned to the variable p. When the button is clicked, some textContent is inserted into the paragraph by an arrow callback. Make up the paragraph text. Don't use brackets in the arrow callback. btn.addEventListener("click", () => p.textContent = "You clicked"); btn\.addEventListener\(•click•,\(\)=>{?p\.textContent=•.*•\)}?;
  1. Code a statement that displays an alert after a 3-second delay. Use an anonymous callback function.
  2. If you've coded correctly, your alert will display after 3 seconds.
  3. Dismiss the alert by clicking OK.
  4. For help with this code, see Chapter 67 in the book.
  1. In the HTML panel, I've coded an empty paragraph and a button. Click the HTML button to see my markup.
  2. Click the Result button to see my markup rendered on the page.
  3. Click the JS button.
  4. In the JS panel, I've assigned the two HTML elements to variables. I've coded a function that fills the paragraph with some text. Below my JS code, call the function when the button is clicked.
  5. Click the Click me button
  6. If you've coded correctly, the paragraph text will appear in the Result panel.
  7. Dismiss the alert by clicking OK.
  8. For help with this code, see Chapter 67 in the book.