Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript JavaScript Basics (Retired) Creating Reusable Code with Functions Passing an Argument to a Function

I've been on this problem for days

What am I doing wrong

Function returnValue(money) { return money} Var echo = money; returnValue("here's ya cash");

Help ya boy out!!

script.js
function returnValue(money){return money}
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>

3 Answers

Steven Parker
Steven Parker
221,309 Points

You were pretty close.

But you don't have a variable named "money", that's just the parameter name in your function. You wouldn't need a variable anyway, you just need to assign echo directly with the result of calling your function. Also, remember that JavaScript is case-sensitive, so "var" must be spelled in all lower case:

var echo = returnValue("here's ya cash");

Thanks for breaking that down fam... this shit was whipping my ass

Benjamin Larson
Benjamin Larson
34,055 Points

The instructions say: Set the value of echo to be the results from calling the returnValue function.

When calling the returnValue function, like this:

returnValue("My String");

it will automatically return the value, because of the return statement you declared in the function. In the above example however, you aren't doing anything to "catch" what it's returning or to save it. It's being returned but since nothing is catching it, it effectively disappears.

So you want to assign the result of calling that function into a new variable--in this case, a variable called echo.

var echo = returnValue("MyString");

If a function returns a value but no variable is there to catch it, does it really return?

I appreciate it fam... does the shit get more complicated? Or does it ease up

Benjamin Larson
Benjamin Larson
34,055 Points

Well...it will certainly get harder. At times a lot harder. But at that same time, things that were once hard become easy and you don't even have to think about them anymore. Learning the fundamentals of any language is daunting at first and you'll probably have times where you feel like you're getting a good handle on things for awhile but then a new concept will be introduced that makes you feel lost all over again.

It's all a matter of how much time and practice you want to commit to it, but there's lots of people here willing to help along the way.

Evgeniia Mas
Evgeniia Mas
4,452 Points

If you really want to return same money, just add semicolon like this return money;