Listing Everibody


#1


Building an adress book 4/6


It prints out in the console "undefined"


Replace this line with your code. 
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<contacts.length; i++) {
        console.log(printPerson[i]);
    };
}
list(contacts)


#2

your function:

var list = function()

doesn't have a parameter, so why does it need an argument when calling the function?

i is just a number:

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

you will need to call printPerson with contacts[i], this way i is used to access the array (var contacts = [bob, mary];) which hold the objects


#3

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