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

Jabor Al thani
Jabor Al thani
2,926 Points

Im stuck on this exercise

I need help with the " How to store the returned results of the function back to the variable ?

script.js
function returnValue (str) { 
var echo = str;
  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>

2 Answers

Steven Parker
Steven Parker
231,072 Points

Don't let the language throw you off.

The phrase "store the returned results...back to the variable" just means "make an assignment". So you will create the variable and assign it at the same time using the assignment operator (equal sign: "="), like this:

var echo = returnValue('hello');

Also, while your function is working as-is, you can simplify it by removing the internal variable and just returning the argument directly:

function returnValue(str) {
    return str;
}
Jabor Al thani
Jabor Al thani
2,926 Points

Thanks for the reply Steve , Its still a little cobfusing for me as its not going through the next stage .

Could you please put the full syntax