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

Call this function, assigning the returned value to a variable that hasn't been declared beforehand. Make up the name of the variable. function returnADozen() {
  return 12;
}
let num = returnADozen(); let[a-z_$][a-zA-Z0-9_$]*=returnADozen\(\);
Assign this function to a variable. Then call the function using the variable. Make up the name of the variable. function sayHi() {
  alert("Hi");
}
const aVar = sayHi;
aVar();
const([a-z_$][a-zA-Z0-9_$]*)=sayHi;[\r\n]\1\(\);
Rewrite this code using a shorthand arrow function. const aVar = function() {
  alert("Hi");
};
aVar();
const aVar = () => alert("Hi");
aVar();
constaVar=\(\)=>alert\(•Hi•\);[\r\n]aVar\(\);
Given the following code, the alert will display "____" function outerFunction() {
  function innerFunction() {
    alert("Hi");
  }
  return innerFunction;
}
const aVar = outerFunction();
aVar();
Hi •?Hi•?
Given the following code, what is the value of aVar? function outerFunction() {
  function innerFunction() {
    alert("Hi");
  }
  return innerFunction;
}
const aVar = outerFunction();
innerFunction innerFunction
Fill in the blank so the alert displays "Hi". Include the indentation. function outerFunction() {
  function innerFunction() {
    alert("Hi");
  }
  ______________
}
const aVar = outerFunction();
aVar();
return innerFunction; returninnerFunction;
Fill in the blanks so the alert displays "Hi". Make up the name of the inner function. function outerFunction() {
  ___________________
    __________
  __
  ________________
  }
const aVar = outerFunction();
aVar();
  function innerFunction() {
    alert("Hi");
  }
  return innerFunction;
function([a-z_$][a-zA-Z0-9_$]*)\(\){[\r\n]alert\(•Hi•\);[\r\n]}[\r\n]return\1;
Code a function that defines a second function and returns the name of the second function. The second function doesn't do anything. Make up the names. function outerFunction() {
  function innerFunction() {
  }
  return innerFunction;
}
function[a-z_$][a-zA-Z0-9_$]*\(\){[\r\n]function([a-z_$][a-zA-Z0-9_$]*)\(\){[\r\n]}[\r\n]return\1;[\r\n]}
  1. I've assigned a function to a variable. Then I've used the variable to call the function. Don't change my code.
  2. Move my code down 2 lines.
  3. Now, above my code, code the function that I call. This function defines a second function, then returns the name of the second function.
  4. The second function displays an alert.
  5. Click the Result button (or, after revising, don't click, just wait).
  6. Wait a moment.
  7. If you've coded correctly, the alert will display.
  8. Dismiss the alert by clicking OK.
  9. For help with this code, see Chapter 59 in the book.
  1. Code a function that defines a second function and then returns the name of the second function.
  2. The second function displays an alert.
  3. Assign the name of the outer function to a variable.
  4. Call the outer function using the variable.
  5. Click the Result button (or, after revising, don't click, just wait).
  6. Wait a moment.
  7. If you've coded correctly, the alert will display.
  8. Dismiss the alert by clicking OK.
  9. For help with this code, see Chapter 59 in the book.