Listing Everybody


#1


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


I get an error message saying: TypeError: Unable to get property 'firstName' of undefined or null reference


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(var i = 0; i<contactsLength; i++);
  printPerson(contacts[i])
}

list();


#2

var contactsLength = contacts.length;
for(var i = 0; i<contactsLength; i++);

#3

Thanks, but still got the error, see edited code.


#4

Hi, I think you need to properly indent printPerson(contacts[i])

As you can see, it's outside the for-loop. It should be inside.

Also, put a semicolon after printPerson(contacts[i])


#5

I removed the semicolon on line 23 (for loop), and it worked but it double printed the address book such as:

Bob Jones
Mary Johnson
Bob Jones
Mary Johnson


#6

Nothing is wrong with your code. Looks like it's Codecademy double checking the code.


#7

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