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

ashique desai
ashique desai
3,662 Points

How to Pass a result of a functions value to a variable?

Have re written this code after getting help from a member from the forum. But still the code is not working, can somebody point out what i am doing wrong? Thanks in advance.

script.js
```JavaScript
var echo = returnValue(hello);
function returnValue(hello) {
    return hello + "How are you?";
}
```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

The problem is you're passing as an argument to the returnValue function a variable called hello that doesn't exists. I think what you want is to pass the string "hello" instead of a hello variable:

var echo = returnValue("hello");
function returnValue(hello) {
    return hello;
}

The code above passes the challenge. I hope it helps.

Many thanks.

Hi,

I hope the following helps.

To complete the challenge, the function returnValue must return just the argument passed to the function. You return:

return hello + "How are you?";

instead of:

return hello;

Calling the function is not neccesary to complete the challenge. However when you do so, you pass to the function a hello identifier (variable name) that does not exits (I think what you wanted to pass was the string "hello" instead of a hello identifier):

var echo = returnValue(hello);

But, in order to complete the challenge, only the following code is needed in script.js:

function returnValue(hello) {
    return hello;
}

Many thanks. Have a nice day,

ashique desai
ashique desai
3,662 Points

Thanks for your help tried the solution you provided like this:

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

Still ain't working! What might be the problem?