We made a friend


#1



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


TypeError: undefined is not an object (evaluating 'person.firstName')


Replace this line with your code. 

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"*/
var contactsLength=contacts.length;
var search=function(lastName){
    for(var i=0;i<contactsLength;i++){
        if(contacts[i].lastName===lastName){
            printPerson(contacts[i]);
            }
        
        
        }
    
    }
search("Jones");

function add(firstName, lastName, email, phoneNumber){
    var contact=new Object();
    contact.firstName=firstName;
    contact.lastName=lastName;
    contact.email=email;
    contact.phoneNumber=phoneNumber;
    }
    contacts[contacts.length]=contact;
    add("Toby", "Smith", "TobySmith.com","605-225-5244");
    list();


#2

This post was flagged by the community and is temporarily hidden.


#3

hmm, where should I put the contacts.push(contact);

in the code?


#4

This post was flagged by the community and is temporarily hidden.


#5

I am getting in the habit of using strictly dot notation with the constructor. Do I have to use literal notation for this exercise to define the object. Also is contract.push an object?