4/6 stuck down


#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);
}

var list = new function()
{
var contactsLength = contacts.length;

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

list.printPerson(contacts);

I've created the following code.
I don't understand why its telling me that list is not a funciton.


#2

This code worked for me

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

list(contacts);


#3

you dont need to call the function 'printPerson' because it is already called in the list function...
list(contacts); should work

also, in the 'for' loop you have for(var i = 0; i < contactsLength-1; i++)

this will print the contact index 0 and stop the loop after printing the first contact.
try just using 'i < contactsLength'


#4

i tried the following code and it worked perfectly,

function list () {
for (var i=0; i printPerson[i];
}
}


#5

You can also use the fillowing code

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