6. We Made a Friend!


#1

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]);
}
}

/Create a search function*
then call it passing "Jones"/*

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

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

add("Guy","Richie","g.r@gmail.com","321 345 325");

list;

Error: TypeError: Unable to set property 'firstName' of undefined or null reference

I can't see the problem here :frowning:


#2

Hey 2 problems @methodwhiz36200! First here:

You dont call a function like that but this:

list();
``` 

Second, in your add function your suppose to make a new object then set that to firstname,lastname,email, and phonenumber. So an example of that is like this(I will do one for you, you do the rest :smile:  )

```
var add = function(firstName,lastName,email,phoneNumber){
    var Somone= new Object();
    Somone.firstName = firstName;
}