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 trialFNU Christian
5,549 PointsCode Challenge: Methods
Hello,
I passed the code challenge with this code:
var genericGreet = function() { return "Hello, my name is " + this.name; }
var andrew = {
name: "Andrew",
greet: genericGreet();
}
var ryan = {
name: "Ryan",
greet: genericGreet();
}
However, it seems wrong to me, and when I want to change it into this, it is wrong:
var genericGreet = function() { return "Hello, my name is " + this.name; }
var andrew = {
name: "Andrew",
greet: function() {
return "Hello, my name is " + this.name;
}
}
var ryan = {
name: "Ryan",
greet: function() {
return "Hello, my name is " + this.name;
}
}
Where did I go wrong?
3 Answers
Sean T. Unwin
28,690 PointsBoth are technically correct, but the first one is correct for the challenge with the following caveat: do not put a semi-colon on the last key-value pair in an object.
Randy Perez
5,668 PointsFirst you are missing a semicolon, on the other and you should know how to access the greet member of your ryan function. good luck
var ryan = {
name: "Ryan",
greet: function () {
return "Hello, my name is " + this.name;
}
};
FNU Christian
5,549 PointsThank you!