6. We made a friend!


#1



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

Can someone please help, this code seems to work for some people!


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

add("A","B","AB@bc.com","555-5555");
list();


#2

Hi this part of your code is fine.... can you post all your code?


#3

Sure!

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

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]);
}
}

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

add("A","B","AB@bc.com","555-5555");
list();


#4

It's missing the search function


#5

yes I took it out because of the 5th instruction "Make sure you call the list function, to check if your new entry is added. And delete any other function that logs output in the console, i.e 'search' function."

Does the search function have to be there in order to work?


#6

Yes you should have the search function you can also try to Save and submit the code and read the error that show up

then this line

var contacts = [bob, mary, add];

you don't need to put add inside the array.. the function add already do that for you.


#7

just took out the (add) in the contacts array and it worked without the search function..

Thank you!


#8

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.