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

Ronald Greer
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Ronald Greer
Front End Web Development Techdegree Graduate 56,430 Points

not sure what to do next on javascript basic Returning value

I've rewatched videos and can't seem to find the answer

script.js
function getYear () {
var year = new Date().getFullYear();
}
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>

2 Answers

Cheo R
Cheo R
37,150 Points

You're close, you just need to do two things:

// return value

function() {
  var variable = functionCall();
   return variable;
}

and the second part is to save it's output in another variable.

var functionCallResult = functionCall();

Hey Ronald,

I'm assuming you're on step 2 of this challenge. You're quite close! In step two, after adding the provided line of code inside the getYear function, it wants you to return the year variable on the next line. If you are unsure of how to do this, maybe give the "Getting Information From a Function" video one more watch.

Side note: watch your spacing and indentation. There should be no space between your function name and the following parentheses. Also, the first line inside your function should be indented by two spaces.

Let me know if you have any more questions!