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 trialAlex Lang
1,110 PointsHelp me understand this a bit better?
Okay so in this code why can't you call it using the ().
for example like this: return year();
instead of
return year;
3 Answers
Zach Swift
17,984 PointsWhen you create a new date and call the getFullYear
method, it returns a number (like 2018
). That is what you're storing in your year
variable. The open and close parentheses are for calling functions. Since the year
variable is just holding a number, there is no reason to call it like a function.
Steven Parker
231,271 PointsThe name "year" in this challenge is a scalar variable, not a function. You are correct that parentheses are added to a function name to call it, but that does not apply to variables that represent values. Those variables are not called, they represent the value assigned to them by their name alone.
Zach Swift
17,984 PointsSteven Parker, it's possible and likely that a variable could be representing a function. In that case, you could call it with parenthesis. But in this case the variable was a number, so no reason to call it.
Steven Parker
231,271 PointsMore than just "no reason", it's not valid syntax to call a variable that represents a value. But you're right that variables can refer to functions. I revised my wording a bit to emphasize the distinction.
Zach Swift
17,984 PointsYou're 100% correct on that.