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

One type of local scope is block scope. The other type of local scope is _______ scope. function function
Block scope has meaning only inside the _______. block block
A variable that has meaning everywhere has ______ scope. global global
In the following code, i has _______ scope. let (i = 0; i < 12; i++) { block block
In the following code, which line won't work? Answer with a numeral, like 1. 1. for (let i = 0; i < numbers.length; i ++) {
2.   let firstNumber = numbers[i];
3.   break;
4. }
5. let total = 10 + firstNumber;
5 5
In the following code, num has _______ scope. function x() {
  let num = 1;
}
function function
In the following code, y has ______ scope. let x = y => y;
let z = x(12);
function function
Code an if statement that tests whether a global variable has a certain integer value. Within the statement, create an integer variable that has block scope. Use const. Make up everything. if (x === 1) {
  const z = 0;
}
if\([a-z_$][a-zA-Z0-9_$]*===(0|-?[1-9][\d]*)\){[\r\n]const[a-z_$][a-zA-Z0-9_$]*=(0|-?[1-9][\d]*);[\r\n]}
  1. If the length of "tiger" is greater than the length of "cat", assign "yes" to a variable that hasn't been declared beforehand.
  2. Using the variable, display the value of the variable in an alert.
  3. Click the Result button (or, after revising, don't click, just wait).
  4. Wait a moment.
  5. If you've coded correctly, an alert will display "yes".
  6. Dismiss the alert by clicking OK.
  7. For help with this code, see Chapter 56 in the book.
  1. Create a global variable that represents an integer.
  2. Code a function that assigns an integer to a second variable.
  3. In the function display the sum of the two variables.
  4. Call the function.
  5. Click the Result button (or, after revising, don't click, just wait).
  6. Wait a moment.
  7. If you've coded correctly, an alert will display the sum.
  8. Dismiss the alert by clicking OK.
  9. For help with this code, see Chapter 56 in the book.