3.Displaying people


I don't understand why I can't make code like that.The Error -

  Oops, try again.
Did you create a function called printPerson?

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

but if I change my code for :

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

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

This code is OK to pass to the next level. Why ? Both of them is OK !    
Where is the problem in the first version of the code?


Yes, both codes are ok just the assignment wants you to create
function printPerson(){} this kind of function that is not saved into a variable.


In the top of my message I comment a part of code ( // function printPerson (person){ ) and then console.log(contacts[person].firstName+" "+contacts[person].lastName);

It's not good code to pass this level.


Oh I see. Yeah the output is the same from both examples just the thing is that challenge parser that checks your code has it own tests that passes your code and determinate if it is good on his standards.
That parser is written by people as an example of checking if you have done it right.
Things like this happen and parser only accepts 1 answer but that doesn't mean that the other code is wrong like in this case.


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