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.
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.
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
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.
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.
After console.log type a semicolon.
Hi, I’m having the same issue.
var bob = {
firstName: "Bob",
lastName: "Jones",
phoneNumber: "(650) 777-7777",
email: "[email protected]"
};
var mary = {
firstName: "Mary",
lastName: "Johnson",
phoneNumber: "(650) 888-8888",
email: "[email protected]"
};
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?
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.
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”…
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.
Use this… Its work for me
var bob = {
firstName: “Bob”,
lastName: “Jones”,
phoneNumber: “(650) 777-7777”,
email: "[email protected]"
};
var mary = {
firstName: “Mary”,
lastName: “Johnson”,
phoneNumber: “(650) 888-8888”,
email: "[email protected]"
};
var contacts = [bob, mary];
function printPerson(person) {
console.log(person.firstName + " " + person.lastName);
}
printPerson(contacts[0]);
printPerson(contacts[1]);
you did not understand my complain…
@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.
thank u…your suggestion helps a lot…
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: "[email protected]"
};
var mary = {
firstName: “Mary”,
lastName: “Johnson”,
phoneNumber: “(650) 888-8888”,
email: "[email protected]"
};
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]);
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.
Thank you for your right answer!
var bob = {
prenom : “Bob”,
nom : “Jones”,
telephone : “01 23 45 67 89”,
email: "[email protected]"
};
var marie = {
prenom : “Marie”,
nom : “Johnson”,
telephone : “02 34 56 78 91”,
email: "[email protected]"
};
var contacts = [bob, marie];
function affichePersonne(personne){
console.log(personne.prenom + " " + personne.nom);
}
affichePersonne(contacts[0]);
affichePersonne(contacts[1]);
var bob = {
firstName: “Bob”,
lastName: “Jones”,
phoneNumber: “(650) 777-7777”,
email: "[email protected]"
};
var mary = {
firstName: “Mary”,
lastName: “Johnson”,
phoneNumber: “(650) 888-8888”,
email: "[email protected]"
};
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
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.
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 + .....