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 trialDarren Kynaston
Courses Plus Student 15,610 PointsJavaScript - Setting 'Method' and calling a separate function through the initial 'Method'.... I'm stuck!
Q: On 'andrew' and 'ryan', set the 'greet' method as the 'genericGreet' function.
Am I mis-reading the question? I am setting the Method to 'greet' and passing the genericGreet function into that Method (well I think I am!) and it's telling me there was "something wrong with the return values".
My answer code is below, any help would be appreciated as I'm starting to pull my hair out! :S
Darren.
<body>
<h1>JavaScript Foundations</h1>
<h2>Objects: Methods</h2>
<script>
var genericGreet = function() {
return "Hello, my name is " + this.name;
}
var andrew = {
name: "Andrew",
greet: function(genericGreet){}
}
var ryan = {
name: "Ryan",
greet: function(genericGreet){}
}
</script>
</body>
1 Answer
Dave McFarland
Treehouse TeacherYou don't wrap the genericGreet
function inside a function. Just assign it like you would any other value like this:
var ryan = {
name: "Ryan",
greet: genericGreet
};
Darren Kynaston
Courses Plus Student 15,610 PointsDarren Kynaston
Courses Plus Student 15,610 PointsThanks Dave,
I couldn't see the wood for the trees on that one. Doh!
Darren.