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

What am I doing wrong in this JavaScript code?

I get this message: Bummer! Hmmm. It doesn't look like you're storing the returned value in the echo variable.

function returnValue( fruit ) {
  var echo = fruit;
  return echo;

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

3 Answers

Bill Hinostroza
Bill Hinostroza
19,273 Points

This is my code and It passes.

var echo;

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


Okay, I had that at first, but was declaring the variable in the wrong place. Thanks for your help.

Steven Parker
Steven Parker
229,005 Points

You were really close!

Task 2 says: "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. "

:point_right: Notice that it says to create the variable after the function, not inside it.

Just put the function back to the way you had it in task 1, and then crreate and assign the new variable when you call your function.

I tried doing it outside of the function and get the same message.

Tobias Helmrich
Tobias Helmrich
31,602 Points

Hey there,

Steven actually already gave you the right solution. I just want to add the code so you can see where your problem might be. Bill's code may pass but he's creating the variable outside of the function and is accessing it in the function outside of its scope which probably isn't the best solution for this challenge.

function returnValue(fruit) {
  return fruit;

var echo = returnValue("apple");

It should work like this, it's just the code for the solution Steven gave you, I hope that helps! :)