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 trialidriss Elouilani
Courses Plus Student 1,232 Pointscreate function
1 create function 2 function getYear (){ var year = new Date().getFullYear(2017); return year; } 3 call the getYear function: store the returned value of the function in current variable named yearToday. 1 and 2 questions works but the 3 question wasn't it
function getYear(){
var year = new Date ().getFullYear(2017);
return year();
}
getYear();
<!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>
3 Answers
Rhys Kearns
4,976 Pointsfunction getYear(){
var year = new Date ().getFullYear(2017);
return year;
}
yearToday = getYear();
From the edits Raffael this should be what you need :)
Raffael Dettling
32,999 PointsYou forgot to assging the getYear function to yearToday
yearToday = getYear();
and in the return statment you return a variable not a function
Rhys Kearns
4,976 Pointsvar yearToday = getYear(); forgot to declare yearToday :)
Rhys Kearns
4,976 PointsNevermind forgot to read it - didn't realise the variable was named already just not pasted into the code! :)
Raffael Dettling
32,999 PointsNo problem thanks to you i found a second bug ^^ in the return statment he returns a function not a variable
Rhys Kearns
4,976 PointsGood spot! Yeah not sure why he is returning a function :P
idriss Elouilani
Courses Plus Student 1,232 PointsThank u Rhys, thank u raffael