We made a friend! need help


#1

I am stuck and can't figure out what's wrong with the code.

function add(firstName,lastName,email,phoneNumber)
{
contacts[contacts.length] =
{
firstName: firstName,
lastName: lastName,
email: email,
phoneNumber: phoneNumber,
}
contacts.push(contacts[contacts.length]);
};
add("name","last","person@ex.com","(888) 888-8888");
list();

calling the list function gives me all three first names with an error message saying
TypeError: Cannot read property 'firstName' of undefined


#2

@dumberthanrocks this is your code corrected below

function add(firstName,lastName,email,phoneNumber)
{
    //this will add new object to end of contacts
    contacts[contacts.length] ={
        firstName: firstName,
        lastName: lastName,
        email: email,
        phoneNumber: phoneNumber //took out comma here
    } ;
    //take this line out
    //contacts.push(contacts[contacts.length]);
}
add("name","last","person@ex.com","(888) 888-8888");
list();