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

The counter name is i. Start it at 0. for (_________; i <= 4; i++) { let i = 0 leti=0
The last element of the array has an index of 9. Fill in the blank, to limit the number of loops. for (let i = 0; _____; i++) { i < 10 i<10
The counter is to increment by 1 after each loop. Fill in the blank. for (let i = 0; i < 10; ____) { i++ i\+\+
What is the keyword that stops a loop? break break
Code the first line of a for loop, starting i at 0 and incrementing by 1 on each iteration. Run it 4 times. for (let i = 0; i < 4; i++) { for\(leti=0;i<4;i\+\+\){
Code the first line of a for loop using a counter name that's not i. Start it at 0. Run it 100 times. Increment by 1 with each iteration. Make up the counter name. for (let trys = 0; trys < 100; trys++) { for\(let([a-z_$][a-zA-Z0-9_$]*)=0;\1<100;\1\+\+\){
Code the first line of a for loop with the usual counter and the usual starting value. Run it 3 times. Increment it by 1 with each iteration. for (let i = 0; i < 3; i++) { for\(leti=0;i<3;i\+\+\){
  1. Code a for loop. Make up the counter name.
  2. Test each element of a 5-element array, answers, to see if it has the value "yes".
  3. If there's a match, a variable, already declared, is assigned a positive, single-digit integer.
  4. Make up the variable name and the integer.
  5. Don't forget the break statement.
for (let i = 0; i < 5; i++) {
  if (answers[i] === "yes") {
    positive = 1;
    break;
  }
}
for\(let([a-z_$][a-zA-Z0-9_$]*)=0;\1<5;\1\+\+\){[\r\n]if\(answers\[\1\]===•yes•\){[\r\n][a-z_$][a-zA-Z0-9_$]*=(0|-?[1-9][\d]*);[\r\n]break;[\r\n]}[\r\n]}
  1. Create an array with 2 integer elements.
  2. Loop through the array to test whether each of the elements matches itself. (It will, of course.)
  3. For each match, display an alert.
  4. Omit the break statement.
  5. Click the Result button (or, after revising, don't click, just wait).
  6. Wait a moment.
  7. If you've coded correctly, the first alert will display and then, when dismissed, the second alert will display.
  8. Dismiss the second alert.
  9. For help with this code, see Chapter 26 in the book.
  1. Create an array with 2 integer elements.
  2. Loop through the array. On each iteration, display an alert whose message is the value of the element.
  3. Omit the break statement.
  4. Click the Result button (or, after revising, don't click, just wait).
  5. Wait a moment.
  6. If you've coded correctly, the first alert will display and then, when dismissed, the second alert will display.
  7. Dismiss the second alert.
  8. For help with this code, see Chapter 26 in the book.