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

JavaScript Function: I can't get pass Task 2 of 2. It keeps saying I'm not storing the "echo" variable.

function returnValue(food){ return food; var echo = returnValue( 'My argument' + food); } returnValue(salad);

script.js
function returnValue(food){
  return food;
var echo = returnValue('My argument' + food);
return echo;
  }
returnValue();
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>

4 Answers

Abe Layee
Abe Layee
8,378 Points

Let take a look at your code

function returnValue(food){
  return food;
var echo = returnValue('My argument' + food);//  'my argument' is food that you passed on  to the function. Therefore, the is no need to call it twice.
return echo; 
  }
returnValue(); 

it should be like this

function returnValue(food){
  return food;
  }
var echo = returnValue('My argument' );// this is storing  the returnValue() into the echo var

Thank you so much :)!! I had been muddling over this for a while. I really appreciate your help.

Will Parry
Will Parry
11,985 Points

So, there are a couple things here. You're calling returnValue() within the declaration of the returnValue() function. You can't do that. Also, in a function, you can only have one return statement.

If the end goal is to have the function return "My argument salad", try this:

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

returnValue("salad");

Thank you for your help. That didn't help. I think something is wrong with the app that checks for the answer.

Thanks for helping.

While there is nothing wrong with using echo as a variable in JavaScript and they may require it in the challenge, I would not make a habit of it. Echo is a key word in PHP. It took me a second to realize that was not an error in JavaScript.