Listing everybody


#1

Hi, i need your help again :))

my code is:

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(i); } };
list(contacts);

the program says it is all good and I can do the next lesson, but
it just printed out :
undefined undefined
undefined undefined
undefined undefined
undefined undefined.

what is wrong in my code?

thanks in advance!!
Vera


#2

undefined is when you access something that wasn't defined.. (duh)

So have a look at where you got it from


#3

That was the opposite of helpful, lonatan.


#5

Look at the function line inside of your for loop,

How does it know where to pull i from? You haven't defined where it needs to look.

Hint: Take a quick second to refresh how to use an array inside of a function


#6

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