Add function not adding new contact - We made a friend


#1

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

I'm not sure what's wrong with this...

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

search("Jones");

function add (firstName, lastName, email, phoneNumber){
    var newContact = {
    firstName: firstName,
    lastName: lastName,
    email: email,
    phoneNumber: phoneNumber
    };
    
    contacts[contacts.lentgh] = newContact;
    
    };
    
    add("first", "last", "email", "444-222-3333");
    list();


#2

@digitalslayer08005,

Have close look at

lentgh


#3

Oh my goodness, thank you so much!