Loops Flashcards

1
Q

Create a loop that runs from 0 to 9 and logs index I to the console.

var i;

A

for (1 = 0; i < 10; i++) {
console.log(i);
}

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

Create a loop that runs through each item in the fruits array, assigns it to an index named x, and logs x to the console.

var fruits = [“Apple”, “Banana”, “Orange”];

A

for (x in fruits) {
console.log(x);
}

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

Create a loop that runs as long as i is less than 10 and log the index to the console.

var i = 0;

A

while (i < 10 ) {
cosole.log(i);
i++
}

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

Create a loop that runs as long as i is less than 10, but increase i with 2 each time logs the index to the console on each loop.

var i = 0;

A

while (i < 10) {
console.log(i);
i = i + 2;
}

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

create a loop that logs index i to console from 0 to 10. But stops if i equals to 5.

A
for (i = 0, 1 < 10; i++) {
console.log(i);
if (i == 5) {
break;
}
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

create a loop that logs index i to console from 0 to 10. But skips the log if i equals to 5.

A
for (i = 0; i < 10; i++) {
if (i == 5) {
continue;
}
console.log(i);
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly