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

Vicki Corich
Vicki Corich
6,632 Points

I can't pass the second part of the challenge.

Here is the question-

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.

Thanks, Vicki

script.js
function returnValue(me){
  var echo = 'hello';
  return echo;
}
returnValue('hello');
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

Hi Vicki, looks like it's asking you to pass the return value into 'echo', so:

function returnValue(me){
   return me;
}

var echo = returnValue('hello');
Jason Anders
MOD
Jason Anders
Treehouse Moderator 145,860 Points

Hi Vicki,

If you're on the 2nd task, then you created the function correctly. Go back to that code and let's work from there.

The 2nd part doesn't ask you to do anything more with the code for the function, so I'm not sure why you put a variable inside the function. The task just wants you to call the function you created.

function returnValue(me) {
  return me;
}

With the function already coded, you call a function by typing it's name returnValue();. This function takes one argument, and the task just wants you to pass in any string and store the functions return value into a variable named echo.

The function is already returning the argument passed in, so to store it in a variable, you would just assign the called function to the variable. var echo = returnFunction("This is me"); This would go outside and after the function itself.

function returnValue(me) {
  return me;

var echo = returnValue("This is now Me!");

Hope this makes sense. Keep Coding! :)

Vicki Corich
Vicki Corich
6,632 Points

Thank you! I finally passed. What's the point of naming the returnValue but not using the name?

This one also stumped me, and I felt really dumb for it. Either I didn't understand the wording of Part 2 or, after a couple of months of dabbling, I don't understand functions at all.

Yeah, I guess I don't understand (without some kind of math equation or puzzle) what we just did there.

I was pretty confused with this Challenge as well. I don't really understand functions that well, but I will keep plugging away.