4. Listing Everybody (I do not noting understand )


#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 - 1; i++) {
        console.log[i];
        console.log(printPerson[i]);
    };
};
list();

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

I was looked at a others forum issues at a same thread. I do not anymore get it what is wrong.
Please, do you have somebody who has a patience to explain me how this code should work?
Thanks. I appreciate the effort. Best.


#2

The above should raise an exception. It also raises an issue in the program. i is only an index, not an object.

console.log(contacts[i])

Likewise in the next line.


#4

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