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

Hunter Ritter
Hunter Ritter
7,747 Points

Function's error

I have added in the code that the instructions stated but it is saying that step 1 gets kicked back. All step 1 wants is to set the function for getYear(). I set it up like: function getYear() { } I think it has something to do with the return statement but I am unsure. I feel completely lost on what I am doing wrong here. Thank You.

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

1 Answer

Steven Parker
Steven Parker
231,271 Points

The "return" statement is currently outside the function, but it needs to be inside the function.

Also, the value you want to return is "year". Returning a call to the function itself would set up an infinite recursion loop.

Hunter Ritter
Hunter Ritter
7,747 Points

Thank you for the help!