4.Listing Everybody


#1


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++);
        console.log(printPerson(contacts[i]));
}

list();


What wrong in this code? I'm getting error like "Oops, try again. Your code threw the following error when trying to call list(): TypeError: Cannot read property 'firstName' of undefined"


#2

your for loop in your list function is missing curly brackets, exmple:
`
for (var i = 0; i < 5; i++){
// loop content
}


#3

ya, thank you so much, it works now :slight_smile:


#4