#6 we made a friend


#1



ok thats my code below

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]);
}
else
{
console.log("Not Found");
}
};
};

search("Jones");

//new code
var add = function(firstName, lastName, email, phoneNumber)
{
contacts[contacts.length] =
{
firstName: firstName,
lastName: lastName,
email: email,
phoneNumber: phoneNumber
};
};
add("Rob", "Tyler", "rob@gmail", "100340" )
list();


its showing this

Bob Jones
Not Found
Bob Jones
Mary Johnson
Rob Tyler

NOW i am not getting email and phone number!! whats wrong!

Continuing the discussion from 6/6 We made a friend!:


#2

HI just remove the call function search() that one

search("Jones");