It says my code is wrong and yet I got the exact result it said. Any reason why?


#1

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


It says my code is wrong and yet I got the exact result it said. Any reason why?


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

printPerson(0);
printPerson(1);

<img src="//codecademy-discourse.s3.amazonaws.com/original/5X/1/6/6/8/1668b6a116c57d8f82ff840a8139cd02cc02283f.png" width="690" height="350">


#2

HI these lines

printPerson(0);
printPerson(1);

where you put 0, 1 you should put contacts[0], contacts[1].


#3

Any idea why it's wrong though? My method prints out the first and last name like it says though :confused:


#4

First this line

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

this part

contacts[person].firstName

should be

person.firstName

and you got the right name because with

contacts[person].firstName

it's also rigtht but they want you to print it the other way.


#5

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