5 TypeError: Cannot read property 'firstName' of undefined


#1



https://www.codecademy.com/en/courses/building-an-address-book/0/5?curriculum_id=506324b3a7dffd00020bf661#


TypeError: Cannot read property 'firstName' of undefined


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() {
	var contactsLength = contacts.length;
	for (var i = 0; i < contactsLength; i++) {
		printPerson(contacts[i]);
	}
}

/*Create a search function
then call it passing "Jones"*/
function search(lastName){
    var contactsLength = contacts.length;
    for (var i = 0; i < contactsLength; i++){
        if (lastName == contacts[i].lastName){
            printPerson(search[i]); 
        }
    }
};
search("Jones");.

Anyone? Help? <3


#2

You're calling printPerson(search[i]), while you should be calling printPerson(contacts[i])