Loop the Loop



My code looks right, the error message is unhelpful...

// Our Person constructor
function Person(name, age) {
    this.name = name;
    this.age = age;

// Now we can make an array of people
var family = new Array();
family[0] = new Person("alice", 40);
family[1] = new Person("bob", 42);
family[2] = new Person("michelle", 8);
family[3] = new Person("timmy", 6);

// loop through our new array
for (i = 0, i < family.length, i++) {


Hello @philhanson,

The aim of this exercise is for you to use JavaScript's for ... in loop. So modify your code so that it iterates over the Array by using a for variable in array loop and you'll be good to go!


I'm sorry, I don't know what you mean...

Edit: You meant change my , to ; in the for loop I take it.


Okay, @philhanson. This is the syntax of a typical for...in loop

var arr =  new Array();
arr[0] = "Allison"
arr[1] = "Bob"
arr[2] = "Charlie"

//Here comes the for...in
for (member in arr) {

The above loop will log to the console: "Allison", "Bob" and "Charlie". You need to modify your code so that it behaves in a similar way. Hope this clears out your problems.


Changing the , to ; in the for loop made it work.


Oh ok... That's not the way I made it work, but I'm glad that it worked none-the-less. Keep coding hard :laughing:!


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