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

Maximilian Dennison
Maximilian Dennison
2,077 Points

Function

Call the getYear function: store the returned value of the function in a new variable named yearToday. I need help Please?

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

getYear(){
var = yearToday(); 
  return year(); 
}
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>

1 Answer

Jordan Stokes
Jordan Stokes
Full Stack JavaScript Techdegree Graduate 22,909 Points

The syntax is wrong. It should be:

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

 var yearToday = getYear();
 ```

The syntax for storing a returned value into a new variable is: var {variable-name} = {funtion-name}();

Also, in general, you seem to not understand JavaScript's syntax. I'd consider going back and reviewing sections.