6/6 "We made a friend!"


#1

Hi there! So this specific chapter here is killing me. I finished the whole thing except for this, and at this point, I think the world simply doesn't want me to finish this, but the thing is I have a deadline (tomorrow) so I would really appreciate an immediate response. Anyway, so here is my code:

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, miles];

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"*/
function search (lastName) {
var contactsLength = contacts.length;
for (var i = 0; i < contactsLength; i++) {
if(lastName === contacts[i].lastName)
{
printPerson(contacts[i]);
}
}
}

var miles = function(firstName, lastName, email, phoneNumber) { contacts[contacts.length] ={
firstName : firstName,
lastName : lastName,
email : email,
phoneNumber : phoneNumber
};
};

add("Miles", "Roman", "isneezedonthebeatandthebeatgotsicker@gmail.com", "(012) 3456789");
list("Miles");

and here is my "mistake":

Oops, try again.
Did you create a function called add?

I even used a debugger and yet here I am. Anyway, I want to thank in advance the kind angel who'll help me.


#2

I don't see an add function anywhere...

It would start like:

var add = function() {

}

#3

It's this one, I just replaces it with a name, but I tried replacing :

with:

and the :

with:

var contacts = [bob, mary, add];

This was the output:

Bob Jones
Mary Johnson
undefined undefined
Miles Roman

and it told me:

Oops, try again.
It looks like you didn't add an person object to the end of your contacts array.


#4

Rename the function add and call add on your new miles contact.

This is what it wants you to do. :slightly_smiling:


#5

God thanks. You are literally a hero from my fated disaster. Kudos to you. :grinning:


#6

Anytime! :wink:

Have fun! :slightly_smiling: