6.we made a friend


#1


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


ReferenceError: 'add' is undefined
Oops, try again. Did you create a function called add?

please help me, I cant find the problem

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 (x=0; x<contactsLength; x++){
        if (search===lastName){
            printPerson(contacts(x));
        }
    }
    
var add=function(firstName, lastName, email, phoneNumber){
        contacts[contacts.length]={
        firstName: firstName,
        lastName: lastName,
        email: email, 
        phoneNumber: phoneNumber
        };
    };
}
add("darrell", "walker","afnh@aol.com", 123-123-1234);
list();


#2

Move the last '}' to close above the function, because you are nesting the add function within the search function. It should close the search function.


#3

thank you so much, it worked like a charm


#4

Here's my code as an extra reference too.

Its fully working.

Hope it helps.


`


#5

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