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 trialSean Lafferty
3,029 PointsDon't know how to do this :(
HELP!
function getYear() {
var year = new Date().getFullYear();
return year();
}
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JavaScript Basics</title>
</head>
<body>
<script src="script.js"></script>
</body>
</html>
1 Answer
Ted Dunn
43,783 PointsYou are asked to return the variable 'year'; the code you have written 'return year()' is treating year as if it were a function (the parentheses after an identifier are only used to call a function). You just need to remove the parentheses and write 'return year'.
In summary:
year == a variable identifier year() == a function call You will usually be returning variables, not function calls.
Kevin Egstorf
26,590 PointsKevin Egstorf
26,590 PointsHi Sean,
First you do not call the function, so it will never run and second you can not
return year()
like that, it is not a function but a variable so it would look like thisreturn year;
. plus it would be better in usingconst
orlet
instead ofvar
I hope this is helpfull if you have anymore questions just let me know.
if you want to output the year in the console it would look like this.