Complete the for Loop
Fill in the Blank Easy
Question
Fill in the blank so the loop prints every element of the array.
Code
const arr = [10, 20, 30];
for (let i = 0; i ___ arr.length; i++) {
console.log(arr[i]);
}
Hint
Valid indices go from 0 to length - 1.
Explanation
Using < ensures i goes from 0 to arr.length - 1 (0, 1, 2), which are the valid indices. Using <= would cause i to reach 3, and arr[3] is undefined (index out of range). The correct operator is <.
Related Resources
Related Lessons
- Loops (for & while)
Learn how for and while loops work.
Look up unfamiliar terms
A beginner-friendly glossary explains jargon in plain English — variables, functions, DOM, Promise, and more.
Decode error messages
Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.
Build real projects
Apply what you learned by building guided projects with starter code and solutions.