Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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,280 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!