Building an address book 6/6


#1

i dont know what did i do wrong if anyone could help me thanks :smiley:
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]);
}
}
var add = function(firstName,lastName,phoneNumber,email){
var contacts[contactsLength] = {
firstName:firstName,
lastName:lastName,
phoneNumber:phoneNumber,
email:email
};
};
/*Create a search function
then call it passing "Jones"*/
var search= function(lastName) {

for( i = 0 ; i < contacts.length ; i ++){
if (lastName = contacts[i].lastName){
printPerson(contacts[i])
};
};
};
search("jones");

add("mohamed","elshazly","01090105440","mohamedelshazly18@yahoo.com");
list();

#2

Hi this part

if (lastName = contacts[i].lastName)

try to change = with ===


#3

hi thanks for your reply but i removed the "var" from this line "var contacts[contactsLength] = { "
and it finally worked !!