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 trialJack Duong
6,324 PointsHaving trouble calling function in console. What did I do wrong?
var genericGreet = {greet:function() {
return "Hello, my name is " + this.name;
}};
var andrew = {
name: "Andrew",
greet:genericGreet
};
var ryan = {
name: "Ryan",
greet: genericGreet
};
I've tried ryan.greet() which gives me "object is not a function"; ryan.greet gives me "Object {greet: function}"
I'm unable to get the return value for the function
1 Answer
Jason Anello
Courses Plus Student 94,610 PointsHi Jack,
The code that you have posted does not pass the challenge for me.
You have correctly set the greet
method to the genericGreet
variable but you should not have modified that variable at the top.
It was set to a function and you have changed it to an object. genericGreet
is no longer a function now but an object.
var genericGreet = function() {
return "Hello, my name is " + this.name;
}
var andrew = {
name: "Andrew",
greet: genericGreet
}
var ryan = {
name: "Ryan",
greet: genericGreet
}
Jack Duong
6,324 PointsThanks! Can't believe I missed that. I really have to work on my attention to detail.
Jack Duong
6,324 PointsJack Duong
6,324 PointsThis is the link to the challenge btw http://teamtreehouse.com/library/methods-3