Displaying People - undefined?


#1


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


undefined undefined

I don't understand what is wrong with my code, how is it undefined?


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

// printPerson added here
var printPerson = function(contacts) {
    console.log(this.firstName + " " + this.lastName);
};

printPerson(0);
printPerson(1);


#2

got it... talked to one of my friends....it's an issue with
A: I need to call the array with [] in the printPerson function and
B: i can't use "this." for some reason....

oh well it works now

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

// printPerson added here
var printPerson = function(contacts) {
    console.log(contacts.firstName + " " + contacts.lastName);
};

printPerson(contacts[0]);
printPerson(contacts[1]);

#3

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