12. "I know someone called undefined" keeps printing


#1

I keep entering this code and I get the same message each time. I am not sure what I need to change. How is the array "undefined"?

var names=["Tay", "Pili", "Hal", "Tom", "Roger"];
for(var i=0; i console.log("I know someone called " + names[i]);
}


#2

Hi its missing your for loop and it should have that strutture

for (statement1, statement2, statement3 ) {
    #do something 
}

#3

Could you explain why this for loop would require an if/then statement?


#4

Sorry error of typing just put for


#5

var names=["Eric", "Pili", "Hal", "Tom", "Roger"];
for(var i=0; i console.log("I know someone called " + names[i]);
}

I am still getting the "undefined" message.


#6

For some reason my code keeps getting cut after I post on this forum.
var names=["Eric", "Pili", "Hal", "Tom", "Roger"];
for(var i=0; iconsole.log("I know someone called " + names[i]);
}


#7

The for loop should be like that

for ( var I =0;

In your second statement you should put

i < names.length

In the third statement you should put the inscrease

i++

Then the console.log should be inside the for loop like that

for (statement1, statement2, statement3 ) {
    console.log("I know someone called " + names[i]);
}

#8

Codeacademy bug.pdf (200.6 KB)


#9

Remove the ; after your for loop statement

for (statement1, statement2, statement3 ); <== this one

#10

Thanks this really helped