Having Trouble With JavaScript Loops


#1

For some reason I'm getting a result saying "undefined" when I run this code. It's supposed to go through each item in myPlaces and log out each place. Can anyone let me know if there's something wrong with my code?

var myPlaces = ['Utah', 'Dallas', 'Chicago'];
var friendPlaces = ['Chicago', 'Texas', 'Virginia'];

for (var i = 0; i < myPlaces.length; i++); {
console.log(myPlaces[i]);
}


#2

Do you mean this output in the console?

Utah
Dallas
Chicago
undefined

#3

Yes. I figured it out it was a simple syntax error. I had to remove the semicolon that was after my for loop


#4

Ah, yes. I was sure you would see that! The list is printing okay, then?


#5

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