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 trialLloyd Lee
3,796 PointsHelp with Javascript Methods Coding Challenge
So the return statement is throwing me for a loop in this coding challenge - I can't seem to figure out the answer. I tried to fix the code to exactly how we learned through the videos, but that's not working (unless I'm missing something).
var genericGreet = {
greet: function () {
console.log("Hello, my name is " + this.name);
}
};
var andrew = {
name: 'Andrew',
greet: genericGreet.greet
};
var ryan = {
name: "Ryan",
greet: genericGreet.greet
};
The original code is:
var genericGreet = function() {
return "Hello, my name is " + this.name;
}
var andrew = {
name: "Andrew"
}
var ryan = {
name: "Ryan"
}
And it's asking to set the 'greet' method on 'ryan' and 'andrew' as the 'genericGreeting' function.
1 Answer
Michael Jurgensen
8,341 PointsHi Lloyd,
You don't have to modify the genericGreet function. Just add a method to each object and attach the genericGreet like this:
var genericGreet = function() {
return "Hello, my name is " + this.name;
}
var andrew = {
name: "Andrew",
greet: genericGreet
}
var ryan = {
name: "Ryan",
greet: genericGreet
}
Lloyd Lee
3,796 PointsLloyd Lee
3,796 PointsThanks for the help Michael - I don't know why I was making it so hard on myself...