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 Passing an Argument to a Function

aliceinwonderland
aliceinwonderland
7,679 Points

i don't understand what i'm doing wrong. please help!

thank you.

script.js
function returnValue(minutes) {
  return minutes;
}
var echo = minutes;

returnValue("60");
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>

3 Answers

Tabatha Trahan
Tabatha Trahan
21,422 Points

Your function is correct. The issue is with setting the variable echo equal to the return value of the function. To do that, you just need to declare the variable, and then set it equal to the value of the function with a string passed to it:

var echo = returnValue("some string");

This way, you are assigning the result of the function to the variable echo. I hope this helps.

aliceinwonderland
aliceinwonderland
7,679 Points

i appreciate your help, tabatha. thank you!

Erwan EL
Erwan EL
7,669 Points

Hi, problem is that you assigned to the variable echo, minutes that is a argument of the function returnValue. If you want to do that, the echo variable needs to be inside the function because minutes is not defined out of the function. You can simply to that:

function returnValue(minutes) {
    return minutes;
  }

  returnValue("60");

Or if you really want your echo variable inside:

function returnValue(minutes) {
    var echo = minutes;
    return echo;
  }

  returnValue("60");
aliceinwonderland
aliceinwonderland
7,679 Points

thank you so much. i appreciate your help!