Loops and Arrays 2 confusion


// Click on "Stuck? Get a hint!" if you get stuck!

var names = ["Person1", "Person2", "Person3", "Person4","Jokes on you, this isn't a name!"];

for (var i = 0; i > names.length; i++); {
console.log("I know someone called " + names[i]);

"I know someone called Joe Dirt"

What am I doing wrong?


This line has 2 problems..
for (var i = 0; i > names.length; i++);
A) the > should be <
B) delete the ; at the end



You are using a semi-colon in the wrong position.
A semi-colon is an End-of-Statement indicator....

for ([initialization]; [condition]; [final-expression]) {

You also have to change your condition
from your

i > names.length


i < names.length


@mr_sommers You sir, are a god. Thank you. Also, the semi-colon at the end was just me messing around trying to figure out if maybe my syntax was off, putting that semi-colon there made the first line of text appear so I figured I was on the right track,





Include the names[i] into your console.log()-Methods-ARGUMENT

console.log( "I know someone called " + names[i] );


Hi, Lenohard, thank you for the feedback, it was very useful.

I had the same problem with the semicolon and now it's solved and I can continue, but I wouldn't like to do so without understanding it clearly.

What was exactly the problem with the semicolon? When I ran the program the only thing appearing was "I know someone called undefined". Why was it undefined, if from the beginning i = 0 and so at least the first name should have appeared? What was the role of the semicolon in that?



The console.log() Method
expects a so-called ARGUMENT

In Javascript you can create a =concatenated-String= with
"I know someone called " + names[i]
and use that as an argument
console.log("I know someone called " + names[i])

In Javascript you use the semi-colon-; as an End-of-Statement indicator
console.log("I know someone called " + names[i]);


google search
== the Book ==
javascript [your question] site:developer.mozilla.org

== discussions / opinions ==
javascript [your question] site:stackoverflow.com

== guidance ==


Thx loads. That ■■■■ ";" haha. Other than that, everything else was dope.