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

A while loop is an alternative to a loop you studied earlier: a ____ loop. for for
In a _____ loop, the counter is always initialized before the loop code begins. while while
i has been assigned 0. Code the first line of the while loop. The loop keeps running as long as i is less than 6. while (i < 6) { while\(i<6\){
I've coded two lines. Code the rest of the while loop. With each loop, add the value of i to total, which has been declared beforehand. let i = 0;
while (i < 100) {
  total = total + i;
  i++;
}
total=total\+i;[\r\n]i\+\+;[\r\n]}
i starts at 0. Code the statement that needs to run above this line of code. while (i < 144) { let i = 0; leti=0;
Code a while loop that runs twice and does nothing. The counter i has already been declared and assigned 0. while (i < 2) {
  i++;
}
while\(i<2\){[\r\n]i\+\+;[\r\n]}
Code the line of a while loop that begins with while. The loop runs as long as i is greater than 10. while (i > 10) { while\(i>10\){
I've declared two variables, assigning values to them. Code a while loop that adds i to tot with each iteration. Use i > 0 as the loop limiter. The loop counts down, decrementing by 1. let tot = 0;
let i = 10;
while (i > 0) {
  tot = tot + i;
  i--;
}
while\(i>0\){[\r\n]tot=tot\+i;[\r\n]i--;[\r\n]}
  1. Using a while loop, code an alert that iterates 3 times, displaying, in an alert, the value of the counter 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.
  5. Dismiss each alert by clicking OK.
  6. For help with this code, see Chapter 63 in the book.
  1. I've coded an array. Leave my code intact.
  2. Below my code, code a while loop that looks for "pig" in the array.
  3. When "pig" is found, an alert displays saying, "Found it!"
  4. Use the length of the array as the loop limiter.
  5. Break out of the loop when "pig" is found.
  6. Click the Result button (or, after revising, don't click, just wait).
  7. Wait a moment.
  8. If you've coded correctly, an alert will display "Found it".
  9. Dismiss the alert by clicking OK.
  10. For help with this code, see Chapter 63 in the book.