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 trialTobias Jackson
9,758 Pointsreturn what ?
This creates a new variable and stores the current year in it. Now, add a statement that returns this variable from the function.
function getYear(){
var year = new Date().getFullYear();
}
<!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>
4 Answers
William Barnes
Front End Web Development Techdegree Student 6,597 PointsA return statement just returns a certain variable from the function, so if you add a " return year; " to the function it will return the value of year.
function getYear(){
var year = new Date().getFullYear();
return year;
}
So then if you were to create a new var called currentYear and call your getYear() function it would return the value "year".
var currentYear = getYear();
Jacob Mishkin
23,118 Pointsyou need to return the value of the variable.
James Anwyl
Full Stack JavaScript Techdegree Graduate 49,960 PointsThis line, creates a new variable (called year) and stores the current year in it:
var year = new Date().getFullYear();
We want to return the variable (year) from the function.
Hope this helps :)
Carlos José
Courses Plus Student 12,431 PointsYou can actually just use the Date class.
var actualDate = new Date();
console.log(actualDate);
console.log(actualDate.getFullYear());
As requested in the challenge
function getYear(){
var year = new Date().getFullYear();
return year;
}
You can assign a Returned value to variables like this : var assign = Function*(arguments, arguments)*;
sebastianlagerblad
5,083 Pointssebastianlagerblad
5,083 Pointsfunction getYear (){ var year = new Date().getFullYear(); return year; }