3. Displaying People


#1

as you can see...
a. the request is done - but the interface said it's not;
b. the interface is asking me if i did created a function called printPerson -but there is!

lame. just lame.


#2

Your code looks odd to me, but I'm not sure if it's technically wrong or not. This is what I used and it worked the first time with no issue:

//BEGIN

   var contacts = [bob, mary];
// printPerson added here
printPerson = function (person) {
    console.log(person.firstName + " " + person.lastName);    
}

printPerson(contacts[0]);
printPerson(contacts[1]);

//END


#5

i was just going deeper in function.
instead of giving to the function as argument the object name,
i gave the position in array.
and it is working perfectly, as it can be seen in output.

my main complain it's about the error msg - inaccurate...
the second it's about the fact that the exercise it's done - working, output excellent - and the interface it's not able to acknowledge that.


#6

I see. I think there are a few of these "gotchas" here on codeacademy (I know I've hit a couple myself). They definitely can be frustrating, but hey it's a free service, so all-in-all pretty great IMHO.


#7

After console.log type a semicolon.


#8

Hi, I'm having the same issue.

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

printPerson(0);

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

How is everyone else getting the right answer?


#9

that was not it.
i filled all semicolons needed.
it just require to go up a level in the function - but it's not explicit and it's not verifying the result corectly.


#10

if you make the function working for any array (not just contacts) and you coll the function with contacts in argument you get the "pass"...


#11

so, (a) you're saying that if it's not payed it's not supposed to be quality... and (b) to entitle yourself as a teacher for others - again - it's not supposing to produce quality material...
I do not agree on any of those points, of course.


#12

Use this.. Its work for me :smiley:

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(contacts[0]);
printPerson(contacts[1]);


#13

you did not understand my complain... :smiley:


#14

@methodplayer78631, bashiros

It appears the problem is the fact that you are calling the function 'printPerson(person)' using 0 and 1 as if it were an array. The array in this exercise is 'contacts' and 0 ,1 refer to the positions of the two objects in it. You can call 'printPerson()' like samandrew81 suggested above ( i.e. printPerson(contacts[0]); ), but I was just trying to figure out what the problem is with your code.


#15

thank u...your suggestion helps a lot...


#16

Does anyone know why the option of "this" can't be used in this exercise? How I should use 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"
};
I noticed that changing "this" for "person", the problem is solved but... does anyone know why or how I should use the "this" in this exercise?

var contacts = [bob, mary];

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

printPerson(contacts[0]);
printPerson(contacts[1]);


#17

I think you can't use this here because the function is not a method, just a free standing function. In this example from the previous Lesson (Introduction to Objects 1), you can see that the function becomes a method for the bob Object with the statement: bob.setAge = setAge;

// here we define our method using "this", before we even introduce bob
var setAge = function (newAge) {
this.age = newAge;
};
// now we make bob
var bob = new Object();
bob.age = 30;
// and down here we just use the method we already made
bob.setAge = setAge;
bob.setAge(50);
// change bob's age to 50 here

Without this association to an object, the function wouldn't be able to figure out what the "this" referred. I think.


#18

Thank you for your right answer!


#19

For French people !

Au cas ou pour les "FR"

(3. afficher des informations sur nos contacts)

var bob = {
prenom : "Bob",
nom : "Jones",
telephone : "01 23 45 67 89",
email: "bob.jones@exemple.com"
};

var marie = {
prenom : "Marie",
nom : "Johnson",
telephone : "02 34 56 78 91",
email: "marie.johnson@exemple.com"
};
var contacts = [bob, marie];

function affichePersonne(personne){
console.log(personne.prenom + " " + personne.nom);
}

affichePersonne(contacts[0]);
affichePersonne(contacts[1]);


#20

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 (person.firstName + " " + person.lastName);
}

printPerson(contacts[0]);
printPerson(contacts[1]);

in printPerson function you used wrong object.property notation, in the description, "print out the person parameter's firstName property by accessing it with a dot just like before. Then print a space, then their lastName in the same way."

see the code which i pasted above, and try again


#21

At first I did the same thing as 'methodplayer78631' did, and wondered why it is not working. I though it's even better solution. Then I realized that the function printPerson would work only for array 'contacts'.

Thanks.


#22

Hello I don't understand in this exercice how and why console.log( person.firstName +...

                   Where  "person" is defined in the exercice ?  never, how the console can identify it then ?

It was logical for me to put              contacts.firstName + .....