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
nikoxyz
10,419 PointsGet year function in JavaScript Basics- store returned value in a variable
I don't know what I'm doing wrong with this, and the text editor button is turned off so I can't run this to check my work.
function getYear () {
var year = new Date().getFullYear();
return year;
}
getYear() {
var yearToday = return year;
}
Also, what am I doing wrong with the code markdown?
2 Answers
nikoxyz
10,419 PointsNever mind. I figured it out based on an answer from the quiz before it. It looks like my markdown worked.
Tim Knight
28,888 PointsI'm glad you were able to figure it out nikoxyz.
For those people who come across this answer I wanted to at least outline a solution and this might help too in your learning process.
Since you've created the getYear() function all you have to do to call the function would be to run:
getYear();
So if you wanted to set that value to the variable you were trying it would look something like:
var yearToday = getYear();
So all together your code would be:
function getYear () {
var year = new Date().getFullYear();
return year;
}
var yearToday = getYear();