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 trialKatrina Brown
3,205 PointsCall the getYear function: store the returned value of the function in a new variable named yearToday.
Call the getYear function: store the returned value of the function in a new variable named yearToday.
7 Answers
Ken Alger
Treehouse TeacherKatrina;
If you post your code when asking questions it is greatly helpful.
With that in mind it sounds like you are on Task 3 of 3, in which case your starting code for that task should look similar to:
function getYear () {
var year = new Date().getFullYear();
return year;
}
Correct?
If you are unclear as to what that function does or how it works, take another look at the videos.
Task 3, which is where it sounds like you are having an issue, states:
Call the getYear
function: store the returned value of the function in a new variable named yearToday
.
So, you just created the getYear
function and do you recall from the videos how to call a function? If not I would recommend going back and watching again, but one can call the function getYear
with:
getYear();
In the case of this challenge, our function will return the current year, so as of today it would be a value of 2014
.
The task also asks to store that value into a new variable named yearToday
. So we need to put into our code:
yearToday = ???; // Need to set the value of ??? to something
That should point you in the right direction, post back if you still are stuck.
Ken
John Mutch
6,962 PointsThis code should work. At least it did for me.
getYear();
var yearToday = getYear();
Good Luck
Alcides Barbosa
2,233 Pointsfunction getYear(){ var year = new Date().getFullYear(); return year; }
var yearToday = getYear();
Jaime Sánchez Blanco
16,894 PointsHi, this worked for me:
function getYear () { var year = new Date() .getFullYear(); return year; } var yearToday = getYear(); if (getYear = = = true) { alert(true)}
Ajay pratap Singh
5,056 Pointsthis is not Worked For me There was an error with your code: SyntaxError: Parse error
Katrina Brown
3,205 PointsSorry. I work it out for myself. Thank you for your help. New to the whole process.
Katrina Brown
3,205 PointsThank u
Unsubscribed User
2,730 PointsTask 3 had me stumped. Parse syntax errors, grrr. I'd recommend re-watching the video. Soon as I did, setting up a function within a variable clicked. Below code worked for me. Hope it helps:
function getYear(){
var year = new Date().getFullYear();
return year;
}
var yearToday = getYear();
Jeff Busch
19,287 PointsJeff Busch
19,287 PointsOK, so what's the problem? Let's see some code.