curriculum/challenges/english/blocks/quiz-javascript-loops/66edcd49e73385dd4df54ac7.md
To pass the quiz, you must correctly answer at least 18 of the 20 questions below.
Which of the following best describes iteration?
It is the process of writing code repeatedly until it works correctly.
It is a technique for storing data in consecutive memory locations.
It is the process of sending signals between components to establish a connection.
It is the process of repeating a set of instructions multiple times.
What technique is used for iterations in programming?
Recursion
Conditionals
Compilation
Looping
Which of the following is an iterable object?
Undefined
Number
Boolean
String
Which of the following is not a type of loop supported in JavaScript?
for loop.
while loop.
for...in loop.
if...else loop.
What is the correct order of the for loop declaration?
for (condition; increment/decrement; initialization) {
statement;
}
for (increment/decrement; condition; initialization) {
statement;
}
for (initialization; increment/decrement; condition) {
statement;
}
for (initialization; condition; increment/decrement) {
statement;
}
Which loop executes the code block once, before checking if the condition is true, and will continue working as long as the condition remains true?
while loop.
for...of loop.
for...in loop.
do...while loop.
Which of the following will loop over the values of an iterable object?
for...in loop.
for loop.
do...while loop.
for...of loop.
Which of the following best defines an infinite loop?
A loop that runs until the condition becomes false.
A loop that runs once and then is terminated.
A loop that automatically stops after a fixed number of iterations.
A loop whose termination condition is never met or is absent.
How many times will the following loop run?
for (let i = 2; i < 10; i+=2) {
console.log(i);
}
5
9
10
4
Which loop is the best for iterating objects?
for...of loop.
do...while loop.
for loop.
for...in loop.
What is the difference between the for...in loop and the for...of loop?
for...in loop iterates over property values, while the for...of loop iterates over property names (keys).
for...in loops create new properties, while for...of loops modify existing properties.
for...in loops can only be used with strings, while the for...of loops can be used with both strings and numbers.
for...in loop iterates over property names (keys), while the for...of loop iterates over property values.
Which of these would cause an infinite loop?
Initialization of variable.
A loop condition that eventually gives false.
Increment/decrement logic.
A loop condition that always returns true.
What statement can be used to break out of a loop completely?
The continue statement.
The label statement.
The skip statement.
The break statement.
Which statement can be used to skip the current iteration and move to the next iteration?
The break statement.
The label statement.
The return statement.
The continue statement.
What is printed to the console with the following code?
for (let i = 0; i < 25; i += 2) {
if (i % 5 === 0) {
continue;
}
if (i % 13 === 0) {
break;
}
console.log(i);
}
0, 2, 4, 6, 8, 12, 14, 16, 18, 22, 24
0, 2, 4, 6, 8, 12
2, 4, 6, 8, 12
2, 4, 6, 8, 12, 14, 16, 18, 22, 24
What would the following code print to the console??
for (let i = 1; i < 6; i++) {
if (i === 4) break;
console.log(i);
}
1, 2, 3, 4, 5, 6
1, 2, 3, 4, 5
1, 2, 3, 4
1, 2, 3
What will be printed to the console with the code below?
const shoppingList = { tomatoes: 4, apples: 10 };
for (const item in shoppingList) {
console.log(item);
}
tomatoes - 4, apples - 10
4, 10
tomatoes:4, apples:10
tomatoes, apples
What will be the console output of the code below?
for (let i = 2; i <= 13; i++) {
if (i % 2 === 0) continue;
console.log(i);
}
2, 4, 6, 8, 10, 12
1, 3, 5, 7, 9, 11, 13
1, 3, 5, 7, 9, 11
3, 5, 7, 9, 11, 13
What would be printed to the console with the code below?
const fruits = ["Mango", "Pineapple", "Oranges"];
for (const fruit of fruits) {
console.log(fruit);
}
0, 1, 2
Pineapple, Oranges, Mango
Oranges, Pineapple, Mango
Mango, Pineapple, Oranges
How many times will the code below output the string in the loop?
let x = 0
while (x < 5) {
console.log("in the loop");
}
3 times
4 times
5 times
Infinite times