27/33 code doesn't work, any tips on it?


#1

// Our Person constructor
function Person(name, age) {
this.name = name;
this.age = age;
}
// Now we can make an array of people
var alice = new Person("alice", 40),
var bob = new Person("bob", 42),
var michelle = new Person("mischelle", 8),
var timmy = new Person("timmy", 6)

var family = [alice, bob, michelle, timmy];

// loop through our new array
for(i=0; i console.log(family[i]);
}


#2

the last part didnt print out right: it should be something like this:
// loop through our new array
for(i=0; i < family.length; i++) {

console.log(family[i].name);
}


#3

You have to use semicolon at the end of each var instead of comma.

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

In the for loop I don't know whether to use console.log(family[i].name); or console.log(family[i]);.
When I tried printing name using dot notation I got the answer but still getting error.


#4

varun_vukkem, you are so close! The problem with your for loop is that you have one of the conditions written as "i <= family.length"; however, if you remember, these loops count starting at "0" so you can set it to "i < family.length." Because "0" is included, it will always be less than the length of "family".

So, the for loop should look like this:
for (var i = 0; i < family.length; i++) {
console.log(family[i].name);
}
Hope that helps!