4. Iterating over an array


#1

not logging any to console

Oops try again. It looks like you didn't log 'HTML' to the console

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


#2

You phrased that almost as if it is printing out all languages except HTML when in fact it won't print any of them. Read your code, try executing it manually.


#3

You're right, I'm just struggling to grasp this for some reason

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

I tried this but it did not work either.


#4

This is where you need to consider what steps it should be executing in order to produce the desired result. And then you need to find out where your program strays from those steps and adjust the code where it did something different.

Code doesn't just work. You need a firm idea of what it's supposed to be doing all the way through, and when it's not doing that, you compare!

The amount of code here is very small, so my suggestion is still to read it very carefully and execute it in your head.

You can also pick it apart further. You have an array, a loop, and a print statement. Those are all incredibly basic things, things that you can look up how they work, how to use them. Can you get those parts working individually?

You may as well practice debugging while you're dealing with very simple code. It's all about narrowing things down until you've got something trivial which you can compare to a reference. You won't ever get things right the first time, we make mistakes. We fix them by reasoning about what we have written.


#5

Remember that within your for loop you'll create a variable . You wrote all its atributes except the variable itself. After that in your console.log you want to print through languages using what you wrote in your for loop.
Hope it helps!


#6

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