27. Loop the loop


I cannot understand whats wrong
We're running a test below to make sure your code works.

TypeError: Cannot read property 'name' of undefined
Oops, try again. Make sure to log to the console the name of each object

// Our Person constructor
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 = 4; i++) {


in your for loop you have:

for( var i = 0; i = 4; i++)

should be

for(var i = 0; i<4; i++)

however I'm getting a similar error and i can't figure it out either.


Well, we know the "for" loop can start on any number and finishes whatever we want, BUT, IN YOUR CASE, IF YOU START THE LOOP ON 0 AND FINISH IT ON 4, its wrong.
You must replace the "for" loop as I recomend you:
for (var i=0;i<5;i++){

On this way, the system will be able the possibility of generating all number that you need.


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