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

What is the keyword that causes an exit from a loop before it's finished iterating? break break
What is the keyword that makes a loop skip the next array element? continue continue
The following statement assigns the number of elements in the array to the variable. Fill in the blank. let num = planets.________; length length
After the following code executes, how many elements have been changed to true? Answer with a numeral, like 1. const x = [false, false, false, false, false, false, false];
for (let i = 0; i < x.length; i++) {
  x[i] = true;
  if (i === 3) {
    break;
  }
}
4 4
Fill in the blank to limit the number of iterations to the number of array elements. The name of the array is guestlist. for (let i = 0; ________; i++) { i < guestlist.length i9Stumpguestlist\.length
What are the elements in the array after the following code executes? Separate the elements by a comma and space. const capitals = ["Stockholm", "Monrovia", "Barcelona", "Rio"];
for (let i = 0; i < capitals.length; i++) {
  if (i > 2) {
    continue;
  }
  capitals[i] = i;
}
0, 1, 2, "Rio" \[?0,1,2,•Rio•\]?
Assign the number of elements in an array to a variable. Make up the name of the variable and the name of the array. let numZips = zipCodes.length; let[a-z_$][a-zA-Z0-9_$]*=[a-z_$][a-zA-Z0-9_$]*\.length;
Fill in the blank so 0 is displayed in the alert; let counter;
for (let i = 0; i < capitals.length; i++) {
  counter = i;
  ______
}
alert(counter);
break; break;
  1. I've created two arrays. Leave my coding intact.
  2. Using a for loop and the continue keyword, fill the second array only with elements that aren't less than 12 in the first array.
  3. Display the second array in an alert.
  4. Click the Result button (or, after revising, don't click, just wait).
  5. Wait a moment.
  6. If you've coded correctly, the alert will display the second array—with nothing but 12 in it.
  7. Dismiss the alert by clicking OK.
  8. For help with this code, see Chapter 29 in the book.
  1. I've created two arrays. Leave my coding intact.
  2. Code a for loop. Stop the number of iterations 3 short of the array length using the length keyword.
  3. Loop through the array, copying elements of the first array into the second array.
  4. Display the second array in 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 the second array—with 4 elements in it.
  8. Dismiss the alert by clicking OK.
  9. For help with this code, see Chapter 29 in the book.