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

Gesang Lamu
Gesang Lamu
2,742 Points

JS Basics Stage5 function challenge

is this asking what I wrote below? Not sure if I can nest function like this, am I thinking too much? Don't laugh if I did something ridiculous.

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.

var echo = function(){

function returnValue(a){

return a; } returnValue("My argument");

};

script.js
var echo = function(){

  function returnValue(a){

  return a;
}
  returnValue("My argument");

};
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>

2 Answers

Hi Gesang,

Your code would look somthing similar to this:

function returnValue(arg){
  return arg;
}

var echo = returnValue('My argument');

You are first creating the function which is passing in the function with:

function returnValue(arg){
  return arg;
}

You are then using this function and passing in your argument with this part:

returnValue('My argument');

Finally you're storing this value in the variable with:

var echo = returnValue('My argument');

Hope that helps

-Rich

Gesang Lamu
Gesang Lamu
2,742 Points

Hi Rich,

That helps a lot!! thank you, thats right, it asking to store the result of the function not literally the entire block of the the function like I did.

No problem. Happy to help :)

Travis Stewart
Travis Stewart
15,188 Points

Thanks Gesang and Rich. Both for posting and for answering. I spent about 10 minutes over-thinking this problem.

No problem :)

Gesang Lamu
Gesang Lamu
2,742 Points

very glad that I posted !! :)