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

Javascript Functions

Can anyone please help me with this. I couldn't fix though it is silly.

Thanks!

script.js
function getYear(){
  <pre><code>var year = new Date().getFullYear();</code></pre>
    return year;
}

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>

3 Answers

Steven Parker
Steven Parker
231,269 Points

It appears that Treehouse has a bug. Tags like CODE and PRE which would normally be invisible and help format the text are being exposed. Those are HTML tags and not for JavaScript. Do not include them in your answer.

And in step 3, remember to assign your function to the yearToday variable.

Dom Talbot
Dom Talbot
7,686 Points

Hey Vishruth

I notice your year variable is wrapped in <pre><code></code></pre>.

As <pre> and <code> are HTML tags, they will cause Syntax errors on runtime.

If you were to remove the tags, your function will run. :)

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

getYear();

Hope this helps!

Dom

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Confirmed. Steven Parker is correct. The HTML in the challenge isn't rendering properly. The `<pre><code>ยด tags shouldn't be there at all. But kudos on following the instructions to the letter! That is most often what causes a challenge to fail. This really needs to be reported to Treehouse.