What is the problem with my code


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

ps, try again. It looks like your list function didn't console.log "Bob Jones". Did you remember to call list(); after creating it?

#2

Bro, I have the same problem, but don't worry we'll figure it out


#3

There are 2 'errors' with your code. Here:

for ( i= 0 ; i< contacts.length ; i++){
    console.log(printPerson[i]);
  };

you should be calling the printPerson function (as in, using it), not logging it;

And here:

list(contacts);

this function doesn't uses variables, so the parentheses should be empty.


#4

Thank you so much, It works


#5

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