Building an Address Book, 4. Listing Everybody


#1



TypeError: Cannot read property 'firstName' of undefined


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);
};
var list = function() {
    console.log(contacts.length);
    for(i=0; i<contacts.length; i++);
    printPerson(contacts[i]);
};
list();


#2

look at this for loop:

for (i = 0; i < 5; i++){

}

see how the for loop uses curly brackets ({}) to mark the start and end of the for loop? the curly brackets are missing in your case


#3

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