How do I write the list function?


#1


https://www.codecademy.com/courses/building-an-address-book/0/4?curriculum_id=506324b3a7dffd00020bf661


Oops, try again. Your code threw a ReferenceError when trying to call list(). Make sure you properly defined the function list! Here's the message: ReferenceError: list is not defined


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 contactsLength = function(){
    for(var i = 0; i < 1; i++) {
        printPerson(1, 0);
    }
};
list();

Thanks For the help


#2

var contactsLength = function(){    // see note 1 and note 2
    for(var i = 0; i < 1; i++) {    // see note 3
        printPerson(1, 0);          // see note 4
    }
};

Note 1

We must first define a list function...

var list = function () {

};

Note 2

This exercise asks us to cache the length of the contacts array:

var contactsLength = contacts.length;

Note 3

To iterate over the entire array, we set the upper limit as the array length:

for (var i = 0; i < contactsLength; i++) {

}

Note 4

The printPerson function takes one parameter, an object:

printPerson(contacts[i]);

#3

I got help on one of my PM's


#4

I need to write the search function now @mtf


#5

The instructions walk us through the steps. Read and follow, then present your problem in a new topic. PM'ing others for individual help is not very helpful to the community. Let everyone take part.


#6

I know but I created the PM for other reasons and he took it to help me with the Javascript


#7

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