Displaying People


#1

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

Error = "Did you create a function called printPerson?" - It shows the correct results (firstname then lastname) and it is still giving me this error.

EDIT = I changed the console.log by removing the contacts[] and just left person and then referenced the array to retrieve the object from the array. I still don't understand how my method was 'wrong' enough though it turned up the correct result?

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

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


#2

console.log(contacts[person].firstName + " " + contacts[person].lastName);
You forget ; after console.log

this is my code

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(person){
console.log(person.firstName + " " + person.lastName);
}
console.log(printPerson(contacts[0]));
console.log(printPerson(contacts[1]));


#3

Interesting... I'm not sure if my way of solving the issue just is not possible or whether I'm just doing something wrong?

I did change the body of the function to include a ; following the console.log, it didn't change anything sadly.


#4

console.log(contacts[person].firstName + " " + contacts[person].lastName)
};
printPerson(0);
printPerson(1);

Instead of calling "contacts[person].firstName" try this:
var printPerson = function(person){
console.log(person.firstName + " " + person.lastName);
}
console.log(printPerson(contacts[0]));
console.log(printPerson(contacts[1]));

I hope it works this time


#5

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