6. We Made a friend! > Building an Address Book


#1

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]);
}
}
}
search("Jones");

var add = function(firstName, lastName, email, phoneNumber) {
add("Diane", "Aguirre", "example@gmail.com", 2111092)
};

list();

Just wanna ask what's wrong here:

It prompts:
Bob Jones
Bob Jones
Mary Johnson

And error as:
Oops, try again. It looks like there are still only two items in the contacts array.

TIA and merry merry Christmas to everyone. sending love to everyone


#2

Remember back to how functions work, It's impossible to call a function from inside the function, and if you're calling a function from inside itself it just throws all kinds of "What in the poop are you doing?" errors.

var add = function(firstName, lastName, email, phoneNumber) {
add("Diane", "Aguirre", "example@gmail.com", 2111092)
};

Try fixing those lines and you should be good to go!