Iterating over an array 4/17


#1

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

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]);


#3

lmao, wow how did I forget that one.

Thanks so much for a quick reply!


#4

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?


#5

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]);
}


#6

@gigaplayer39868

You've spelt languages wrong in your loop.


#7

Thanks.

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


#8

Thanks for the help. It help me too!


#9

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

What I did wrong??


#10

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]);
}

#11

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


#12

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++
};


#13

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