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 trialDwayne Munro
Front End Web Development Techdegree Student 13,108 Pointshow to do returning a value from a function
how to solve task 3
function getYear() {
var year = new Date().getFullYear();
return year;
}
var yearToday
getYear();
year = 2016;
<!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
Jennifer Nordell
Treehouse TeacherHi there! You're doing great and you're on the right track. You set up the yearToday variable and then on a new line you call the getYear function. The getYear function is going to look up the current year and then send it back to the piece of code that called it. But you never do anything with the returned value. Take a look:
function getYear() {
var year = new Date().getFullYear();
return year;
}
var yearToday = getYear();
This last line does two things. It sets up our variable yearToday. Then it calls the getYear function. The getYear function will deterimine the year and send it back. That year now gets assigned as the value of our yearToday. Hope this helps!
Dwayne Munro
Front End Web Development Techdegree Student 13,108 PointsThanks it worked!
Ashish Mehra
Courses Plus Student 54 PointsAshish Mehra
Courses Plus Student 54 PointsHey Dwayne Munro, In 3rd task they only asked you to call function and assign return value to var yearToday