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 trialDevanshi verma
1,307 PointsI am not understanding the concept of returning the value.
how to complete this code?
function getYear() {
var year = newDate().getFullYear();
return getYear;
}
<!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>
4 Answers
Dan Oswalt
23,438 PointsThink of a function as a machine. You put something in, it does some work, you take something out. In code, that will often look like input > calculation > output. If we care about what our function machine is outputting, we can save that result by having the function 'return' a variable or piece of data.
Your function inputs a new Date object, the machine stores the year of that Date into a variable called 'year', and you want to return that output by returning 'year' variable, as shown by Jeff.
Dan Oswalt
23,438 PointsAlso, to get it to work, you have new Date() as newDate(), it has to be separated:
function getYear() {
var year = new Date().getFullYear();
return year;
}
Jeff Jacobson-Swartfager
15,419 PointsNice! Good eyes!
Devanshi verma
1,307 Pointshey Dan!! thanks for help but I dont know for what reason they are not letting this pass.
Devanshi verma
1,307 Pointsthanks Dan my code finally worked, guess I have problem with the next code.
Jeff Jacobson-Swartfager
15,419 PointsThe value it is asking you to return is year
. So, you can just
return year;
within the function's code block to pass this step of the quiz!
Devanshi verma
1,307 PointsI am sorry, but it is not working. can you help?
Jeff Jacobson-Swartfager
15,419 PointsAbsolutely. Return year
instead of getYear
. So, you can use
function getYear() {
var year = new Date().getFullYear();
return year;
}
to pass.
Devanshi verma
1,307 Pointsthank you for helping again jeff but the code dont seem to work, I used the exact code.
Devanshi verma
1,307 PointsThanks jeff, it worked finally, I have a problem with the next code I posted it on my forum, you gotta help me through that!!!