What is wrong with my code?


#1

i Know this can be done in another way but what is worng with this one?

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(i=0; i if(contacts[i].lastName === lastName){
printPerson(contacts[i]);
}
}
};

search("Jones");

var add = function(firstName,lastName,email,phoneNumber){
this.firstName = firstName;
this.lastName = lastName;
this.email = email;
this.phoneNumber = phoneNumber;
};

contacts[contacts.length] = add;

add("Lawrence", "Eagles", "lawrenceagles@gmail.com", 0938374746);


#2

@lawreneagles,

If you would change your

contacts[contacts.length] = add;

add("Lawrence", "Eagles", "lawrenceagles@gmail.com", 0938374746);

into

contacts[contacts.length] = add("Lawrence", "Eagles", "lawrenceagles@gmail.com", 0938374746);