Could some one explain why I'm getting this error?


#1


My code works, but I get the error "TypeError: Unable to get property 'firstName' of undefined or null reference", and Code Academy won't let me continue. What's going on?


var bob = {
    firstName: "Bob",
    lastName: "Jones",
    phoneNumber: "(650) 777-7777",
    email: "bob.jones@example.com"
};

var mary = {
    firstName: "Mary",
    lastName: "Johnson",
    phoneNumber: "(650) 888-8888",
    email: "mary.johnson@example.com"
};

var contacts = [bob, mary];

function printPerson(person) {
    console.log(person.firstName + " " + person.lastName);
}
function list() {
    contactsLength = contacts.length
    for(var i = 0; 0 < contactsLength; i++) {
        printPerson(contacts[i])
    }
    
}
list()


#2

the condition in your for loop:

0 < contactsLength

this will always be true? zero won't increase, you might want to use i instead


#3

Ah cheers. I knew it must be something like that, it was driving me mad - Silly mistake!


#4