1
2
3
4
5
6
7
8
9
10
To practice on your own, or to check code you believe shouldn't have been scored as incorrect, go to CodePen.
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\); |
|
|||
|