Confused on what to do We Made A Friend


#1

Im confused on what to put inside the add function. (In this new function, you want to create a new contact object like bob and mary. Instead of having this object's property values be filled with strings though, set them to the appropriate function parameters passed in.)
Should i do a this ? Im a bit lost

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]);
}
}
}
function add (firstName, lastName, phoneNumber,email) {

search("Jones")


#2

Without having done the exercise or having read the instructions, I'd say that your add function should create an object of the same structure as mary and bob, but only store them in the contacts list since that's what the other functions use. (as opposed to creating separate variable names for them, like bob and mary has)

If you had a million persons, it wouldn't be very convenient to clutter up your namespace with a name for each of them, but having a list of a million person-objects is perfectly manageable.