[SOLVED]We Made A Friend. I'm getting an error popup but everything seem to work fine


#1



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


I don't know what's wrong, at least the output I get from the console is what I expect.
But i'm getting this popped up;

Oops, try again.
Make sure that the search() function still exists! Your code threw
the following error when checking if you called search():
ReferenceError: search is not defined

here's the 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]);
    }
}

function add(firstName, lastName, phoneNumber, email) {
    var contactsLength = contacts.length;
    contacts[contactsLength] = new Object();
    contacts[contactsLength].firstName = firstName;
    contacts[contactsLength].lastName = lastName;
    contacts[contactsLength].phoneNumber = phoneNumber;
    contacts[contactsLength].email = email;
}

add("Carol", "Peletier", "(316) 666 2523", "carol@thewalkingdead.com");

list();

I removed the search function definition and any calls to this function just as suggested in the instructions;

05. Make sure you call the list function, to check if your
new entry is added. And delete any other function that logs output in
the console, i.e 'search' function.

Run the code!

Any help will be much appreciated.


#2

You need the "search" function

var search = function(lastName) {
    var contactsLength = contacts.length;
    for(var i = 0; i < contactsLength; i++) {
        if(lastName == contacts[i].lastName) {
            printPerson(contacts[i]);
        }
    }
}

#3

Yup, that worked fine,
Thanks.