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

Hassan Noueilaty
Hassan Noueilaty
3,713 Points

Challenge Task 2 of 3: "It looks like Task 1 is no longer passing."

Hello,

I'm receiving the following message when I execute my code:

"Oops! It looks like Task 1 is no longer passing."

However, I didn't change any of the code from task 1. I wasn't sure if the return statement had to be entered in the function, or outside of the function.

Thanks!

-Hassan

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

return getYear();

Here's what the question is asking:

Challenge Task 2 of 3

Inside the function's code block add this line of code

var year = new Date().getFullYear();

This creates a new variable and stores the current year in it. Now, add a statement that returns this variable from the function.

1 Answer

Florian Tönjes
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Florian Tönjes
Full Stack JavaScript Techdegree Graduate 50,856 Points

Hi Hassan,

you almost got it. Just put the return statement into the function.

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

Kind Regards, Florian