for loops Flashcards
What are the 5 characters missing from this code, excluding any spaces that are missing? Type them in order, with no spaces or commas between them. for var i = 0 i <= 4 i++
The correct answer:
(;;){
The line should be coded:
for (var i = 0; i <= 4; i++) {
Use the conventional counter name and the usual count start to fill in the blank.
for (_________; i <= 4; i++) {
Sorry, the correct answer is: var i = 0
The loop is to run 10 times. Fill in the blank, using either of the 2 acceptable ways to specify the number of loops. for (var i = 0; \_\_\_\_\_; i++) {
Sorry, that’s incorrect. The correct answer:
i <= 9
or
i < 10
The counter is to increment after each loop. Fill in the blank. for (var i = 0; i <= 9; \_\_\_\_) {
i++
Code the first 15 characters of a for loop with the usual counter name and usual starting value.
for (var i = 0;
Code the first line of a for loop with the usual counter name, usual starting value, and usual increment. Run it 12 times using <= to specify how many loops.
The correct code: for (var i = 0; i <= 11; i++)
Code the first line of a for loop with the usual counter name, usual starting value, and usual increment. Run it 4 times using < to specify how many loops
for (var i = 0; i < 4; i++) {
Code the first line of a for loop with a counter name that’s not i. Code the usual starting value and usual increment. Run it 100 times using < to specify how many loops.
for (var x = 0; x < 100; x++) {
Code the first line of a for loop with the usual counter and the usual starting value. Run it 3 times using > to specify how many loops. Decrement it with each iteration.
for (var i = 0; i > -3; i–) {
Code a loop using the usual conventions and < that displays an alert containing a string 50 times.
for (var i = 0; i < 50; i++) { alert("Crazy yet?"); }
Code a loop using the usual conventions and < that tests each element of a 5-element array, answers, to see if it has the value “yes”. If so, a variable, already declared, is assigned a positive, single-digit integer. Use a number, not the array length, to limit the number of loops.
for (var i = 0; i < 5; i++) { if (answers[i] === "yes") { positive = 1; } }
for (var i = 0; _____; i++) {
i <= 9
or
i < 10