4.iterating over an arrray


#1

Help!
this is my code:

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

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

and it prints out:
[ 'HTML', 'CSS', 'JavaScript', 'Python', 'Ruby' ]

the error message is:

Oops, try again. It looks like you didn't log 'HTML' to the console!
BUT I DID!
thanks in advance


#2

Actually, you printed the whole array, but the console wants to see each item by itself. If you want to print one item by itself, for example the first one, you'd say:

console.log(languages[0]);

You want to print items in the array that are from languages[0] to languages[4] (you have 5 items and the first position of an array is 0). Try fixing your for loop to iterate through the correct numbers and print

console.log(languages[i]);

instead of the whole list.


#3

thank you!:slight_smile: this helped me a lot