for loops Flashcards

1
Q
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++
A

The correct answer:
(;;){
The line should be coded:
for (var i = 0; i <= 4; i++) {

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Use the conventional counter name and the usual count start to fill in the blank.
for (_________; i <= 4; i++) {

A
Sorry, the correct answer is:
var i = 0
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q
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++) {
A

Sorry, that’s incorrect. The correct answer:
i <= 9
or
i < 10

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q
The counter is to increment after each loop. Fill in the blank.
for (var i = 0; i <= 9; \_\_\_\_) {
A

i++

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Code the first 15 characters of a for loop with the usual counter name and usual starting value.

A

for (var i = 0;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

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.

A
The correct code:
for (var i = 0; i <= 11; i++)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

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

A

for (var i = 0; i < 4; i++) {

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

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.

A

for (var x = 0; x < 100; x++) {

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

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.

A

for (var i = 0; i > -3; i–) {

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Code a loop using the usual conventions and < that displays an alert containing a string 50 times.

A
for (var i = 0; i < 50; i++) {
  alert("Crazy yet?");
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

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.

A
for (var i = 0; i < 5; i++) {
  if (answers[i] === "yes") {
    positive = 1;
  } 
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

for (var i = 0; _____; i++) {

A

i <= 9
or
i < 10

How well did you know this?
1
Not at all
2
3
4
5
Perfectly