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

Task1 is no longer passing

In Task 2 of 3 I'm supposed to copy and paste some code into the function I created in the first Task and return the variable year. When I submit my code I get the error "Oops! It looks like Task1 is no longer passing." I'm honestly confused. If I'm not supposed to put anything inside the function from task 1, then why tell me to paste a line of code into the function?

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

2 Answers

That seems odd you're not allowed to put anything inside the function. The whole point of the function is to return the current year...

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

I've tried everything I can think of. Which isn't a whole lot, given the limited code in this task, but still. No matter what I put inside that function, I always get the same error.

Well I just restarted chrome, did the task the exact same way as I did before, and now it suddenly works...

Huzzah! Strange, but glad you got it worked out.