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

Ronald Greer
Ronald Greer
33,399 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

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();
Ronald Greer
Ronald Greer
33,399 Points

Thank you Cheo, you and Matt really helped

Matt Hanson
MOD
Matt Hanson
Treehouse Moderator 17,825 Points

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!

Ronald Greer
Ronald Greer
33,399 Points

Thank you so much Matt, you and Cheo really helped!