6/6 Adding New Contact To Address Book Error


#1

I've been trying to figure this one out for a couple of days now & I can't seem to get it. The error message is: "It looks like your new contact doesn't have a firstName property."

Any help would be appreciated!

Here's the code I have:

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

  function add (firstName, lastName, email, phoneNumber) {
     var  contacts = {
        firstName: firstName,
        lastName: lastName,
        phoneNumber: phoneNumber,
        email: email
        }    
}
 
 contacts[contacts.length] = ["Larry","Lebowski","(206) 666-0009","larry@aol.com"];

list();

#2

This is the line that declares and defines contacts:

var contacts = [bob, mary];

This line erases that array and replaces it with a plain object:

var  contacts = { // ... }

This line appends an array to the contacts array when it should be appending an object.

contacts[contacts.length] = [ // ... ];

We can use this last line (in part) in the function...

contacts[contacts.length] = {
    // ...
};

The call would be reflective, as well...

add("Larry","Lebowski","(206) 666-0009","larry@aol.com");