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 trialAndrew Hickman
11,602 PointsJavaScript Methods Question
Hi,
I'm having some trouble getting through the JavaScript Methods code challenge. It asks to set the "greet" method as the genericGreet function, and I'm not sure if I'm doing this wrong or misunderstanding the question. Here is my code:
var genericGreet = function () {
return "Hello, my name is " + this.name;
}
var andrew = {
name: "Andrew"
greet: genericGreet()
}
var nick = {
name: "Nick"
greet: andrew.greet
}
Thanks for any help!
3 Answers
eck
43,038 PointsYou nearly have it right, it looks like the only thing wrong is you are missing a couple commas.
Try this code:
var andrew = {
name: "Andrew",
greet: genericGreet()
};
var nick = {
name: "Nick",
greet: andrew.greet
};
EDIT: You should also end your object declarations with a semicolon as a best practice.
Andrew Hickman
11,602 PointsYes, thank you so much! That was it!
victor guia
8,098 Pointsmy solution to the challenge is the same as the solution given above (except that the second name is ryan instead of nick). however, I am still getting an error. please help.
var genericGreet = function() { return "Hello, my name is " + this.name; }
var andrew = {
name: "Andrew",
greet: genericGreet()
};
var ryan = {
name: "Ryan",
greet: andrew.greet
};