Part 12: Introduction to 'For" Loop in JS Error


#1


https://www.codecademy.com/courses/javascript-beginner-en-NhsaT/2/4?curriculum_id=506324b3a7dffd00020bf661


Oops, try again. Your code should have printed 'I know someone called Brendan', but didn't. Make sure to type the 'I know someone called ' part exactly right, and don't forget the space between that phrase and the name!
I can't seem to find what's wrong. I've looked over it to what feels like 100 times, and this still comes up!
Look, I'm going to feel stupid afterwards...


var names = ["Brendan", "Ike", "Jill", "Winona", "Lance"]

for (var i = 0; i == names.length; i++) {
    console.log("I know someone called " + names[i]);
}

Blockquote


#2

Here:

for (var i = 0; i == names.length; i++) {

The second condition should be i < names.length, not i == names.length. The code within the for loop will run as long as the second condition is met. Because i == names.length is currently false, the code will not run.


#3

Ah, I knew I would feel stupid. Thank you very much.


#4

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.