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

JavaScript JavaScript Basics (Retired) Creating Reusable Code with Functions Returning a Value from a Function

When I check my work on Task 3 it says Task 1 is no longer passing, but when I retry Task 1 it says it is correct.

Unsure of where I'm going wrong.

script.js
function getYear()  {
  var year = new Date().getFullYear();
  return year;
}

var yearToday = getyear();
index.html
<!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>

Task 1 is create function getYear

1 Answer

Steven Parker
Steven Parker
231,269 Points

You were really close!

Your function name is "getYear" (with a capital "Y"), but when you called it, you used the name "getyear" (with a lower-case "y").

Since "getyear" is not defined, it caused a syntax error, which invalidates the entire script. And as the challenge re-checks the tasks in order, it interpreted it as a task 1 failure.

Ah wow! I was so focused on my character usage that my eyes must have skipped over that. Thank you!