We Made a Friend: 'It looks like there are still only two items in the contacts array.'


#1

https://www.codecademy.com/courses/building-an-address-book/0/6?curriculum_id=506324b3a7dffd00020bf661#

I cannot figure this out for the life of me. Looked at tons of other posts on this specific exercise and still can't get it. Please help. Thank you.

"Oops, try again. It looks like there are still only two items in the contacts array."


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

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

contacts[contacts.length] = add('dylan', 'king', '555-555-5555', 'dylan@gmail.com');

list();


#2

here:

lastName: lastname,

lastname is undefined, variable names are case sensitive.

the add function will add the contact to array, so doing contacts[contacts.length] when calling the add function is a bit too much

your search function from earlier exercise is missing


#3

thank you beautiful soul I have fixed it. :heart_eyes:


#4