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

Type the last character in a do…while loop. ; ;
The loop stops executing before i reaches 11. Fill in the blank. } while ______; (i < 11) \(i<11\)
The counter has been assigned a value. Start a do...while loop by coding the first line. do { do{
The counter has been assigned a value. Code the first 3 lines of a do...while loop that displays the counter, i, with each iteration. With each iteration, the counter increments by 1. do {
  alert(i);
  i++;
do{[\r\n]alert\(i\);[\r\n]i\+\+;
Code the last line of a do…while loop that runs as long as the counter is under 5. } while (i < 5); }while\(i<5\);
I've declared two variables and assigned values to them. Code a do...while loop that adds i to tot with each iteration, using +=. Decrement the counter by 1. Use i > 0 as the loop limiter. let tot = 0;
let i = 10;
do {
  tot += i;
  i--;
} while (i > 0);
do{[\r\n]tot\+=i;[\r\n]i--;[\r\n]}while\(i>0\);
Code a do...while loop that displays the counter value with each iteration. Begin with the statement that initializes the counter. Count up. Make up the name of the counter. Make up the value of the loop limiter. let j = 0;
do {
  alert(j);
  j++;
} while (j < 10);
let([a-z_$][a-zA-Z0-9_$]*)=(0|-?[1-9][\d]*);[\r\n]do{[\r\n]alert\(\1\);[\r\n]\1\+\+;[\r\n]}while\(\1<(0|-?[1-9][\d]*)\);
Below is an array definition. Code a do...while loop that looks for "pig" in the array. When "pig" is found, an alert displays: "Found it!" The loop continues as long as the counter hasn't reached 5. Break out of the loop when "pig" is found. Use the most common loop limiter name, counting up from 0. let animals = ["horse", "ox", "cow", "pig", "duck"]; let i = 0;
do {
  if (animals[i] === "pig") {
    alert("Found it!");
    break;
  }
  i++;
} while (i < 5);
leti=0;[\r\n]do{[\r\n]if\(animals\[i\]===•pig•\){[\r\n]alert\(•Foundit!•\);[\r\n]break;[\r\n]}[\r\n]i\+\+;[\r\n]}while\(i<5\);
  1. Using a do...while loop, code an alert that loops 3 times, displaying the value of the counter in an alert each time.
  2. Click the Result button (or, after revising, don't click, just wait).
  3. Wait a moment.
  4. If you've coded correctly, three alerts will display the changing counter value.
  5. Dismiss each alert by clicking OK.
  6. For help with this code, see Chapter 64 in the book.
  1. I've coded an array. Leave my code intact.
  2. Below my code, code a do...while loop that looks for "Tigers" in the array.
  3. When "Tigers" is found, an alert displays saying, "Tigers has index number [whatever its index number is] in the array."
  4. Use the length of the array as the loop limiter. Break out of the loop when "Tigers" is found.
  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 64 in the book.