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 trial

JavaScript JavaScript Basics (Retired) Creating Reusable Code with Functions Returning a Value from a Function

create 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

script.js
function getYear(){
  var year = new Date ().getFullYear(2017);
  return year();
}
getYear();
index.html
<!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

function getYear(){
  var year = new Date ().getFullYear(2017);
  return year;
}
yearToday = getYear();

From the edits Raffael this should be what you need :)

You forgot to assging the getYear function to yearToday

yearToday = getYear();

and in the return statment you return a variable not a function

var yearToday = getYear(); forgot to declare yearToday :)

Nevermind forgot to read it - didn't realise the variable was named already just not pasted into the code! :)

No problem thanks to you i found a second bug ^^ in the return statment he returns a function not a variable

Good spot! Yeah not sure why he is returning a function :P

Thank u Rhys, thank u raffael