Logging to the console


#1

If we want to print the third element of an array, do we need to put console.log()?

When I wrote this code the answer still printed javascript to the console.

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

languages[2];

#2

console.log(languages[2]); is how you would print out "JavaScript" :slightly_smiling:


#3

Oh, sorry, see your question now. Well, I am not really sure if that's correct. You say languages[2]; worked?


#4

yes it did. Maybe it's just that the instructions said "log"?


#5

@mccbjnn That may be so! I just tried it that way and it worked. I don't think this is proper, but it's interesting that it works.


#6

For goodness sake. Here.

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


#7

What exactly do you mean? Do you realize how inconvenient this method you are using is? It defeats the whole purpose of the for loop.


#8

Here:

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


#9

I still passed it. And why are you scolding me for passing?


#10

What is the need for this?

Also, I didn't "scold you for passing," so I don't know where you got that idea.