6. Not able to make new friend


#1



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


Not able to understand where I'm going wrong. Also, really confused between the different notations that are being used to create the "add" functions in the forums. My code is working fine till the search function. The last part, i.e the "Add" part i'm not able to solve even after referring to the existing solutions in the forums. Please help.

I tried this first

var add = function (firstName, lastname, email, phoneNumber) {
    contacts[contacts.length] = {
        this.firstName: firstName,
        this.lastname: lastName,
        this.email: email,
        this.phoneNumber: phoneNumber
        };
    };
    
add("first", "last", "ab@ab.com", "238947238947");

This doesn't work too.

var add = function (firstName, lastname, email, phoneNumber) {
    contacts[contacts.length] = {
        firstName: firstName,
        lastname: lastName,
        email: email,
        phoneNumber: phoneNumber
        };
    };
    
add("first", "last", "ab@ab.com", "238947238947");

Tried a couple of other variants as well to no avail.


#2

The second method should work, except that you have a small typo. Compare:

var add = function (firstName, lastname, email, phoneNumber) {
//                               --^

with:

contacts[contacts.length] = {
    firstName: firstName,
    lastname: lastName,  // <-- oops!
    email: email,
    phoneNumber: phoneNumber
    };
};

:wink:


#3

Thanks a lot man. Had a feeling it was going to be a capitalisation issue as I had checked so many answers and the format and syntax was strikingly similar.

Thanks a lot again.