Iterating over an array 4/17

This is my code, but it says “Oops, try again. It looks like you didn’t log ‘HTML’ to the console!”

    var languages = ["HTML", "CSS", "JavaScript", "Python", "Ruby"];

    for (var i = 0; i < languages.length; i++) {
       console.log(i);
    }
2 Likes

In your console.log, where did the “i” come from? The problem in that code is that they do not know WHERE.

You have to add where, like this:

console.log(languages[i]);

4 Likes

lmao, wow how did I forget that one.

Thanks so much for a quick reply!

1 Like

i got stuck for a moment on this too but managed to figure it out, while i was stuck i kept trying things. i logged in the same code as above but at one point i put
console.log(languages++) and i passed the test. it logged NaN but i knew that wasnt what i was supposed to log. my question is why did it work, if its clearly not what i should have done?

1 Like

I am stuck on this one… not sure where I’ve made an error. Can anyone help me debug this code?

var languages = [“HTML”, “CSS”, “JavaScript”, “Python”, “Ruby”];

for (var i = 0;i <= langauges.length;i++) {
console.log(languages[i]);
}

1 Like

@gigaplayer39868

You’ve spelt languages wrong in your loop.

1 Like

Thanks.

Not gonna lie… definitely feeling like a idiot right now. lol

1 Like

Thanks for the help. It help me too!

1 Like

var languages = [“HTML”, “CSS”, “JavaScript”, “Python”, “Ruby”];
for( var i = 0; i < languages.length; i++);
console.log(languages[i]);

What I did wrong??

1 Like

Hi try to add a { } at the for loop and remove the ` ``;``` after the for loop LIke that

for( var i = 0; i < languages.length; i++) {
console.log(languages[i]);
}
1 Like

figured it out already, but thanks for help :slightly_smiling:

1 Like

This my original code that works! Try It! I did a confusing route but I knew it was unclear and basically wrong but still right. I got my correct solution thanks to you guys though. :slightly_smiling:
var languages = [“HTML”, “CSS”, “JavaScript”, “Python”, “Ruby”];
for (var each = 0; each < languages.length; each++) {
console.log(languages[0]);
languages++
};

1 Like

var languages = [“HTML”, “CSS”, “JavaScript”, “Python”, “Ruby”];
for( var i = 0; i < languages.length; i++){
console.log(languages[i]);
}