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 trial
Gina Sabori
8,664 PointsJavascript Foundations > Objects > Methods Code Challenge
I"m really pretty lost with what this code challenge is asking.
On 'andrew' and 'ryan', set the 'greet' method as the 'genericGreet' function.
var genericGreet = function() {
return "Hello, my name is " + this.name;
}
var andrew = {
name: "Andrew"
}
var ryan = {
name: "Ryan"
}
The stuff I put in just came back "Bummer! Null".
3 Answers
Chase Lee
29,275 PointsJust take out the parenthesis after the function call.
Sebastian Abondano
4,666 PointsNice. Thanks, this helped. Stupid commas!
Chase Lee
29,275 PointsJust like name, you should have greet. And just like the strings you should have the function. I hope that wasn't to cryptic for you.
Gina Sabori
8,664 PointsWhat is wrong here.
var genericGreet = function() {
return "Hello, my name is " + this.name;
}
var andrew = {
name: "Andrew";
greet: genericGreet();
}
var ryan = {
name: "Ryan"
greet: genericGreet();
Chris Akers
2,527 PointsG S,
In andrew and ryan, you want a reference to the genericGreet function. But when you put the parenthesis after the function name, genericGreet(), then you actually immediately execute the function instead of saving a reference to the function in the object. Removing the parens should solve the issue.
Gina Sabori
8,664 PointsThanks Chris, that worked. I think it was also because I didn't put a comma after 'name: "ryan"' and 'name:"Andrew"', and also I didn't need semi-colons.
var andrew = {
name: "Andrew",
greet: genericGreet
}
var ryan = {
name: "Ryan",
greet: genericGreet
}