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 trialJohn Gilmer
Courses Plus Student 3,782 PointsNot sure what im getting wrong lol
Not sure what it wrong, I think it's a problem returning the function, must of forgot how to return a function
function getYear() {
var year = new Date().getFullYear();
}
return function 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>
2 Answers
Bryan Knight
34,215 PointsThe first step is to create the empty function:
function getYear(){}
Step two add the line var year = new Date().getFullYear();
inside the function and return the variable year.
function getYear(){
var year = new Date().getFullYear(); //this adds the requested line
return year; //this returns the year variable
}
Step three call the getYear function and store the returned value in a variable called yearToday.
function getYear(){
var year = new Date().getFullYear();
return year;
}
var yearToday = getYear(); //this creates a variable named yearToday and sets it equal to the value returned from calling (also known as invoking) the function getYear. You call (or invoke) a function in javascript by putting the function name followed by an open in closed parenthese () for example: getYear()
Nick Trabue
Courses Plus Student 12,666 PointsIt wants you to put the return in the function so that when you call the function it will actually return the year. Without the return in the function it wouldn't really do anything other than store the variable year.
function getYear() {
//store a variable that will get the year
var year = newDate().getFullYear();
//return that variable when the function is called
return year
}