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

In the following code, the 9 is the element's ____. (one word) someNumbers[9]; index index
When JavaScript does its automatic numbering, the starting index is __. 0 0
Create a new array, nums, comprising three numbers from 3 to 5. Use the syntax you learned in the book. const nums = [3, 4, 5]; constnums=\[3,4,5\];
Specifying an index on the array below, code an alert that displays "Gail". const names = ["Alf", "Bo", "Gail"]; alert(names[2]); alert\(names\[2\]\);
Create an array with two elements, both strings. The array hasn't been declared beforehand. Make up the array name and the strings. const airlines = ["Italia", "Emirates"]; const[a-zA-Z0-9_$]*=\[•.*•,•.*•\];
Assign to a variable the first element of an array. The variable hasn't been declared beforehand. Make up the variable name and the array name. let mealExpense = expenses[0]; let[a-z_$][a-zA-Z0-9_$]*=[a-z_$][a-zA-Z0-9_$]*\[0\];
Create an array with three elements: a number, a string, and a variable. Make up everything. const list = [1, "one", one]; const[a-z_$][a-zA-Z0-9_$]*=\[[-]?(?:[.]\d+|\d+(?:[.]\d*)?),•.*•,[a-z_$][a-zA-Z0-9_$]*\];
Create an array with two string elements. Then assign the last element in the array to a variable. The variable hasn't been declared beforehand. Make everything up. const socialNets = ["Instagram", "TikTok"];
let net2 = socialNets[1];
const([a-z_$][a-zA-Z0-9_$]*)=\[•.*•,•.*•\];[\r\n]let[a-z_$][a-zA-Z0-9_$]*=\1\[1\];
  1. Assign a three-element array to a variable.
  2. Display an element of the array 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 the element you intended.
  6. Dismiss the alert by clicking OK.
  7. For help with this code, see Chapter 21 in the book.
  1. I've created an array on the first line. Without changing the first line, add a new element to the array.
  2. Use the array to display the new element 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, the new element will display in an alert.
  6. Dismiss the alert by clicking OK.
  7. For help with this code, see Chapter 21 in the book.