Can anyone explain this code


Why did this work? I am actually not sure :disappointed:

Can anyone explain this.

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

for(var languages = 0; languages < 5; languages++){


we have two things here: languages, which is an array

then we have a for loop, in which we are going to use a counter, but you give the counter the same name as the array, are you certain you want to do this?

whatever you call your counter, you should use your counter as index to retrieve items from the array:


can you provide the exercise url?

If you need more help, also post an updated version of your code please


Yes the hints say the answer should be this but I still got my top one right. Is there any differences. This is what code academy wanted.

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


well, given your array and the counter the same name is a bad idea.

you hard-coded 5 in the loop condition, what if the array changes size? then length would be a better choice (its better to learn good habits early)

your code only output numbers ,not elements from your array, is this the desired result?


Oh yeaahhhh that's actually a good idea instead of typing how many elements are thanks for the support


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