4. Listing Everybody- help please!


#1


I'm not sure what I'm doing wrong. Can anyone help please? I'm sure it's something really simple that I'm overlooking....


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( i= 0; i < contactsLength; i++)
    printPerson(contacts)[i]);
}
};
list;


#2

Nevermind I solved it! One too many brackets were placed!


#3

This one worked;

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

list;


#4

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