Iterating over an array


#1

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

for (var i = 0; i < languages.length; i++) {
// console.log the 'i'th element
// of the languages array
console.log(i);
};

This is my code, what I don't understand is why it is telling me HTML is not being logged when the index starts from 0 that is logged to the console. Does it mean the word HTML is not being logged?

So confusing codeacademy.

I am starting from 0


#2

Hi your console.log should be like that console.log(languages[i])


#3

Hello wizmarco, thank you again, tell me how much Javascript experience do you have?

So far I have about 30 days experience and I wish there was a way to learn faster.

I have taken out textbooks, been given books to read, watched videos etc.

Any resources you would recommend?


#4


#5

Hi I've finished JavaScript for a while now....but I'm leaning other cours... I think you yet got any resouces I would recomend you.


#6

In my experience, one learns the fastest by trying things out and learning from you mistakes. If you don\t have any "code" background (like me) JS is a great place to start.
I warmly recommend also: https://github.com/getify/You-Dont-Know-JS


#7

thank you at Puristaja, I will check out the link. Thank you for the resource! smile:

How long have you been coding for?


#8

For over a year now. It gets easier :slightly_smiling:


#9

here is another way to do it

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


#10

That may be a way to do it but you're just console.logging the answers anyway

The exercise wants you to write a for loop to do it,
from what you wrote the only thing thats actually good is the for loop

then why not use console.log(languages[i])
meaning you only have to write 2 lines rather than writing 6 more.


#11

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

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