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

Passing an argument to a function, objective #2 I can't seem to make this work.

I can't seem to make this work. Please help.

script.js
function returnValue(anything) {
  var echo = anything;
  return echo;
}
returnValue("I hope this works.");
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

You have all the parts, just not in the right places. The echo variable needs to be outside the function, to receive the result of calling the function.

So, after moving things around a bit it might look like this:


:warning: SPOILER ALERT


function returnValue(anything) {
  return anything;
}
var echo = returnValue("I hope this works.");

I like your sense of humor, I think I also named my argument "anything". :smile:

Thank you Steven. Problem solved.

anil rahman
anil rahman
7,786 Points

It says after your function do the echo you did it inside the function.

function returnValue(value)
{
   return value;
}

var echo = returnValue("hello");

Thank you Anil.