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 trialSeth Brotherton
13,481 PointsCan't figure out what I'm doing wrong. I feel like I've tried everything. What's wrong?
When I add the last line, it then says Task 1 is no longer correct. What about the last line invalidates the rest of the code? What am I doing wrong?
function getYear() {
var year = new Date().getFullYear();
return year;
}
getYear()
var yearToday = 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>
1 Answer
Steven Parker
231,248 PointsTypically, a "Task 1 is no longer correct" message means you've introduced a syntax error. Since that invalidates the entire script, the re-checker interprets it as task 1 failing.
In this case, the syntax error is caused by trying to assign an undeclared variable named "year". But you should replace that with a call to your function anyway.
David Moody
19,302 PointsDavid Moody
19,302 PointsYou need to call the function inside the variable yearToday. Change your last line of code to:
var yearToday = getYear();
I just ran that through the challenge. It should work for you. Get rid of the other time you called the function getYear().