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

functions

Please fix this problem.

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

It is asking you to create a variable of echo outside of the function, and setting it to the value returned in the function.

If you make echo = name within the function, you can not use echo anywhere else. I'll give you a hint below. I hope that helps!

function returnValue(name){
  return name;
}

var echo = ?;

1 Answer

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

You're really close here! The echo variable is to be defined outside of the function and contain the result of calling the function. The only thing in the function should be the return statement which returns what you originally passed into it. Outside the function echo is declared and then we call/invoke/execute the function taking the string we pass to it. The function returns the string which then resides in our new echo variable. Take a look at your modified code to see what I mean:

function returnValue(name) {
  return name;
}

var echo = returnValue("Anu");