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

Courtney Meza
Courtney Meza
2,403 Points

Can't return the variable from the function

I've tried numerous different ways, including console.log(); at the end and alert(); I've tried new Date() as well as newDate() in case it was an error. What am I missing?

function getYear(){
  var year = new Date().getFullYear();
return getFullYear();
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  <title>JavaScript Basics</title>
<script src="script.js"></script>

2 Answers

Steven Parker
Steven Parker
173,890 Points

The created variable is named "year", but the return statement is trying to pass back the result of calling "getFullYear()" as a function instead.

To return the variable:

    return year;