4.Listing Everybody


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);

function list() {
        var contactsLength = contacts.length;

    for (contacts=0; contacts<contactsLength; contacts++);


It says I passed the exercise but it's obviously wrong since the console logs pleanty of "udefined". What is going on?


first thing is here, you need to use a { instead of a semicolon because that is proper syntax, it should look like

for(contacts = 0; contacts < contactsLength; contacts++) {


also, inside of the for loop, you need use the line


you don't need to console.log printPerson because that function already has a console.log line, and you need to use contacts[contact] because contacts is an array that you are iterating through.


Thanks! but it still won't work because I haven't define i anywhere actually :slight_smile: so I will try to do it this way, with the i variable, not using contacts variable


You're right sorry, it should be contacts[contact], I just use i in my code


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