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

Jose Esplana
Jose Esplana
12,503 Points

I need help solving this Challenge Task 2 of 2

Could someone please show me. I still couldn't solve this problem.

Thank you for your help!

function returnValue(price){
  var echo = price + 'dollars';
  return echo;
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  <title>JavaScript Basics</title>
<script src="script.js"></script>

3 Answers

function returnValue(exampleString) { return exampleString; }

var echo = returnValue('exampleString');

sorry it took so long I had to go to a meeting

Having looked at the challenge from the given link above, this is what I have for both task one and two.

The exampleString is simply my example but you can feel free to use your own argument values there. Make sure that upon task two, you use the exact same spelling in the ' single quotes as you have used in both returnValue and return parenthesis as you have used in Task One.

Jose Esplana
Jose Esplana
12,503 Points

Hi Michelle, Thank you! for your help. Why is that var echo is outside the block { }?

What is the question given to you on the task? - Thanks

hmm good call and actually, I don't know! I just noticed in the example for this video before the task:


that Dave had placed arguments out side the braces, he does it a lot in the video as well. He must explain that part some where in the video but in my time zone it is far too early for me to be functioning haha. Maybe someone else will know the answer you are asking for . :D

Jonathan Grieve
Jonathan Grieve
Treehouse Moderator 91,253 Points

You need to return the parameter variable rather than echo.

The function is a little more complicated than it needs to be. All you need is to provide an argument, (which you did) and then return that argument. Remember arguments in functions are just like variables which are used as placeholders for values.

When the function is complete, then you need to call the function with the string value used as it's argument. This is where you need to use the echo variable by assigning the function call to it. :)