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 is the Problem in my code ?

function returnValue(max) {
  var echo = 'My argument';
    return echo ;
}
Dave McFarland
Dave McFarland
Treehouse Teacher

Hi,

To put code into a forum post use triple back ticks -- ``` — around the code. I fixed your code here, but in the future here's a forum discussion that describes how to add HTML, CSS, JavaScript or other code to the forum: https://teamtreehouse.com/forum/posting-code-to-the-forum

6 Answers

Stephen Bone
Stephen Bone
12,359 Points

You've already created your function so then all you need to do it call it. As below:

// here is your function used to pass the first challenge
function returnValue(max) {
  var echo = max;
  return echo;
}

// then you call it and assign it to the variable
var echo = returnValue('abc');
Stephen Bone
Stephen Bone
12,359 Points

Just try it again I updated the code a few seconds ago and wonder if you happened to try it while I changed it.

I left the closing brace in the wrong place.

Stephen Bone
Stephen Bone
12,359 Points

Hi Durul

You have to return the argument that is passed into the function, in your case max not set the variable echo to the string 'My argument'.

Your code should be as below

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

Hope it helps!

You have to call the function outside of the braces, passing 'My argument' to it. Basically it asks you to this.

function returnValue(n){
  return n; // you should use a more descriptive argument in general though
  }

var echo = returnValue('My argument');

thank you very much. I got it.... :)

You are welcome.

the question is 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.

but my code is not still working

I could not take green light.

Stephen Bone
Stephen Bone
12,359 Points

So the method for calling a function is to type the function name followed by the argument you want to pass into it in parenthesis.

And then to complete the challenge you need to pass this back into a variable named echo such as below:

var echo = returnValue('abc')

it is not work.

function returnValue(max) { var echo = returnValue('abc') return echo; }