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 trialPurvi Agrawal
7,960 PointsHaving a Hard Time to understand the Question and the Instructor !
The Question is :
On 'andrew' and 'ryan', set the 'greet' method as the 'genericGreet' function.
My code :
var genericGreet = function() { return "Hello, my name is " + this.name; }
var andrew = {
name: "Andrew"
}
var ryan = {
name: "Ryan"
}
var greet = andrew.genericGreet;
var greet = ryan.genericGreet;
It says : Bummer! The 'greet' method on 'andrew' and 'ryan' should be the 'genericGreet' function.
4 Answers
Jason Atkinson
26,245 Pointsgreet is a method not a variable so it doesnt need to set a variable, heres another way to think about it:
<script>
var genericGreet = function() { return "Hello, my name is " + this.name; }
/* or you can also try */
function genericGreet() { return "Hello, my name is " + this.name; }
/* they should do the same thing */
var andrew = {
/* adding a comma then include the greet method and set it to genericGreet being
CAREFUL about CAPS you dont need to put the () after the genericGreet function
as the function was already created above */
name: "Andrew",
greet: genericGreet
}
var ryan = {
name: "Ryan",
greet: genericGreet
}
</script>
if thats not working im not sure what else the problem can be.
Jason Atkinson
26,245 Pointshint: the greet: needs to be inside the variables Andrew and Ryan not on there own. (greet: GenericGreet ) greet is also a method not a variable
Purvi Agrawal
7,960 PointsHi Jason, Thank You for the reply. I did that too when I was trying but it is giving me a Syntax Error. Not sure what I am doing wrong.
Here is the code : var greet : genericGreet
Is this how we will write ?
Purvi Agrawal
7,960 PointsThank You Jason !! It worked.
Jason Atkinson
26,245 Pointsyer!!! success :)