3. Displaying people


#1

Hi,

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

When I call this code it says: "Oops, try again. It looks like your function didn't log "Bob Jones" to the console. Did you remember to call your function on bob?" And on the black window it says: "undefined undefined". I wonder what is wrong with it?

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 = [0, 1];

// printPerson added here
var printPerson = function (person) {
    console.log(person.firstName + " " + person.lastName);
};
console.log(printPerson[0]);
console.log(printPerson[1]);

#2

first off, your contacts array:

var contacts = [0, 1];

should actually hold your contacts:

var contacts = [bob,mary];

now we can use this on our function call, lets see what you have at the moment:

console.log(printPerson[0]);

a function call requires normal brackets:

console.log(printPerson("X"));

this will pass an argument into the function call. Now, we need to access the first item of our contacts array, and pass this as function argument.


#3

Ok, now it works, thanks. There is a text on green "Way to go!" and on the black box it reads: "Bob Jones undefined
Mary Johnson undefined".


#4

wow, you made it to work. Most of the time people need more help when my answer is just a push in the right direction, truly, well done :slight_smile:

oh, the instructions warn you for this:
Don't worry if your output appears twice - we're just double checking your code!

Your code works fine, i got the same output.


#5

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