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 trialValerie Smith
Courses Plus Student 5,244 Pointsfunction name and return value do not have to be the same correct?
I am struggling on question two of placing the new variable and the return function into the code block of the getYear function. How should I structure this?
function getYear() {
var year = newDate().getFullYear();
return year;
}
<!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>
3 Answers
Brian Jensen
Treehouse Stafffunction getYear() {
var year = new Date().getFullYear();
return year;
}
var yearToday = getYear();
Raphaël Seguin
Full Stack JavaScript Techdegree Graduate 29,228 PointsYour code is right. First, you have to store the value returned by the "newDate().getFullYear()" function in the variable "year", and then return the value of this variable.
function getYear() {
var year = newDate().getFullYear();
return year;
}
Valerie Smith
Courses Plus Student 5,244 PointsThanks. Unfortunately it will not accept that answer...
Raphaël Seguin
Full Stack JavaScript Techdegree Graduate 29,228 PointsIt worked for me too... strange !
Valerie Smith
Courses Plus Student 5,244 PointsValerie Smith
Courses Plus Student 5,244 PointsThanks Brian! that second variable was where I got hung up.
** Update. Tried it your way. Says step one of creating the function is wrong now.