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

Yifang kuo
Yifang kuo
Front End Web Development Techdegree Student 12,376 Points


HERE IS THE QUESTION After your newly created returnValue function, create a new variable named echo. Set the value of echo to be the results from calling the returnValue function. When you call the returnValue function, make sure to pass in any string you'd like for the parameter.

The function will accept the string you pass to it and return it back (using the return statement). Then your echo variable will be set with what is returned, the results.

function returnValue(fruit) {
  return fruit;


var echo =returnValue();
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  <title>JavaScript Basics</title>
<script src="script.js"></script>

2 Answers

David Morisset
David Morisset
13,323 Points

the problem is with the last two lines of the javascript. Firstly, you call returnValue('apple'); without assigning it to a variable, which means that the value it returns will be lost. Secondly, you assign returnValue() to echo without passing an argument.

For doing what you want to do, you need only one line, and it will look something like this :

var myVar = returnValue('myValue');

It's the best explanation i can give you without giving the full answer ;) Hope this helps

Full Stack JavaScript Techdegree Student 16,610 Points

The problem is with your function call inside script.js.

//1. You call the function and pass the string apple.
//2. The function returns apple back.
//3. Nothing gets done with the returned value.

var echo =returnValue();
//1.  You call the function and pass nothing.
//2.  Inside the function, the variable fruit has nothing stored
//              so it passes back a special string 'undefined'.
//3.  Undefined is returned and assigned to echo.

Instead you need to do a bit of both. Call the function with 'apple' and save the return value to echo.