Address book 4/6. pls review and help me


#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];

var list=function()
{
var contactsLength=contacts.length;
for(var i=0;i<[contacts.length]-1;i++)
{
function printPerson(person) {
console.log(person.firstName + " " + person.lastName);
}
}
};

list();


#2

1 ) Hi, firstly you should search through array.length

for(var i=0;i&lt;contacts.length;i++)

2) your printPerson function declaration should be out side of the for-loop.

    function printPerson(person) {
console.log(person.firstName + " " + person.lastName);
}

var list=function()
{
var contactsLength=contacts.length;
for(var i=0;i< [contacts.length]-1;i++)
{
printPerson(contacts[i]);
}
};

#3

Sorry, but ->
var contactsLength=contacts.length;
for(var i=0;i< [contacts.length]-1;i++)

bad style. Correct:

var contactsLength = contacts.length;
for (var i = 0; i < contactsLength; i++)
or
var contactsLength = contacts.length;
for (var i = 0; i < contacts.length; i++) {