HELP! Loop the Loop 27 - I'm lost!


#1

I'm lost at the loop part on this exercise. Please help and if there anything else that might be wrong. My code is below:

// 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] = Person("alice", 40);
family[1] = Person("bob", 42);
family[2] = Person("michelle", 8);
family[3] = Person("timmy", 6);

// loop through our new array

for(i = 0; i < family.length, i++){
console.log(family[i].name);
};


#2

should be

for(i = 0; i < family.length; i++)

and

you have to create a new instance


#3

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

/*this.disp = function() {
    return this.name + " : " this.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("mi8helle" 8);
family[3] = new Person("timmy" 6);

//console.log(family[3]);

// loop through our new array

//console.log(family[0]);

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

for (i = 0; i < family.length; i++) {
//family[i].disp();
console.log(family[i].name);
//console.log(family[i]);
}

I have written this. but its editor tells there is some syntax error. Can this editor be give some specific about error and its information


#4

I haven't looked into it but I could imagine that there are millions of variations of what could be wrong with a certain piece of code and if the js interpreter would have to check a piece of code against every one of them, to find the exact problem --- it would take a very long time.

use a comma to separate your values.


#5

For those seeking the solution here it is.

var Person = function(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 (var i = 0; i < family.length; i++) {
console.log(family[i].name);
};


#6

Please. refrain from posting answers as it against forum rules, as seen here.