Unit 7 - Lesson 6


#1



https://www.codecademy.com/pt-BR/courses/javascript-beginner-pt-BR-3ui28/0/6?curriculum_id=5355c2d8516bcbd912000009


"TypeError: Cannot read property 'length' of undefined"


Replace this line with your 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"
};
function add(firstName, lastName,phoneNumber,email){   
   contacts[contacts.length] ={       
        firstName : firstName,
        lastName: lastName,
        phoneNumber : phoneNumber,
        email: email,
    };
}

var contacts = [bob, mary, contacts[contacts.length] = 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]); 
	}
}


list();
add("Pessoa","grazi");


#2

@patigc,
Change your

var contacts = [bob, mary, contacts[contacts.length] = add];

into

var contacts = [bob, mary]

#3

@leonhard.wettengmx.n,
Thanks for answer!

But here, I want to create new object and add in array contacts automatic.