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 solve this JavaScript challenge

Need to add a 'var echo' and add the result of the function to it. Plus add a string. I do not know how to do it. Please help me in solving this code challenge. Thanks.

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

1 Answer

Steven Parker
Steven Parker
231,007 Points

:point_right: You can only use return inside a function.

To call a function, you use the function name followed by parentheses enclosing any arguments.

So in this case, instead of return str you might write returnValue("my string")

ashique desai
ashique desai
3,662 Points

Thanks for your help. Thanks for correcting me with respect to not using "return" outside of function. Tried the solution advised by you. But that solution is not working. I used returnValue(str); also tried returnValue(); but it is not working. Can you suggest any other solution?