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

function returnValue(str) { var echo = return str; } How to pass and store the results in a var echo?

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

How to pass and Store the results of the function in a variable named echo.

Now that you've created the returnValue function, call it, by passing it a literal string value -- a series of characters in quote marks like this: 'My argument'. Store the results of the function in a variable named echo.

script.js
function returnValue(str) {
  var echo = 
  return str;
}
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>

5 Answers

Abe Layee
Abe Layee
8,378 Points

In anthoer word, create a var echo outside the function and pass the function name to it. Something like this. Your code is almost right except that the echo var needs to be outside the function and pass the returnValue() to it.

function returnValue(one) {
    return one;
}
var echo = returnValue("My argument");

Ok so all your function is going to be doing is returning something. Outside of your function you need to assign the "call" (returnValue()) to the variable echo. Make sense?

It worked. Thanks!

Zack Guo
Zack Guo
12,135 Points

Here is my solution:

function returnValue(food){
  return food;
}
var echo = returnValue("beef");