3. Displaying people - I don't see why this won't work


#1

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

My initial answer gets an error message "Oops, try again. Did you create a function called printPerson?".

This is the initial answer:

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

This is the correct answer:

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

Both gets the same result printed. I assume the difference between the two is how you define the parameter person . Is my initial answer incorrect, or is it just because only the second answer is programmed to be correct?


#2

Both are correct, but the exercise seems to be programmed to only approve the second one.


#3

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