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

Steve holcomb
Steve holcomb
1,931 Points

I cant seem to get this one correct. What am I missing?

What am I missing here?

script.js
var returnValue = function (blah) {

 return blah;
 var echo = blah
};

returnValue("yo");
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

The problem is that the challenge wanted the echo variable to be created outside of the function that you had created, but yours was inside it instead. Also because the return statement immediatly stops that function and returns to wherever called it, it would never actually be created.

To set the variable echo to the value of the function all you need to do is declare the variable and then call the function, like this:

var returnValue = function (blah) {
     return blah;
};

 var echo = returnValue("yo");