Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialTRILOK NAGAR
306 PointsOn 'andrew' and 'ryan', set the 'greet' method as the 'genericGreet' function.
Please give me answer of this code
5 Answers
Dino Paškvan
Courses Plus Student 44,108 PointsAll you have to do is add a property (method in this case) called greet
to both objects and point it to the genericGreet
function. Something like this:
function genericMethod () {
// do something
}
var myObject = {
someProperty: "something",
myMethod: genericMethod // We use the genericMethod function as a property of this object
}
Tom Lawrence
8,685 Pointsinterested in this also, stuck!
Dino Paškvan
Courses Plus Student 44,108 PointsWhy don't you post what you've attempted so far as Jason Anello suggested?
Caio Moretti Marques
Courses Plus Student 27,922 PointsI'm having some trouble to do this Challenge too. I was trying by calling the function and using "apply" on it, like this:
greeting.apply(andrew, args1);
But is not working. How can we deal with it?
Sergio Alen
26,726 Points var genericGreet = function() {
return "Hello, my name is " + this.name;
}
var andrew = {
name: "Andrew",
greet: genericGreet
};
var ryan = {
name: "Ryan",
greet: genericGreet
};
andrew.greet();
ryan.greet();
Joy Singharath
5,425 PointsI believe if you leave out "andrew.greet();" and "ryan.greet();"... your code should be fine. I don't think the task is asking for an output.
Jason Anello
Courses Plus Student 94,610 PointsJason Anello
Courses Plus Student 94,610 PointsWhat have you tried so far?
Posting code in the forum