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

Ryan Amansec
Ryan Amansec
1,962 Points

Set the value of echo to be the results from calling the returnValue function

I'm stuck trying to set the results of returnValue to the variable "echo"

function returnValue(name) { var echo = name; return echo; }

returnValue("Rayray")

script.js
function returnValue(name) {
  var echo = name;
  return echo;
}

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

3 Answers

james south
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
james south
Front End Web Development Techdegree Graduate 33,271 Points

echo doesn't go in the function, it goes after and outside it. your function can just return the parameter 'name', you don't have to put that in another variable just to return it. then just point your call of the function to your variable and it will store the return value of the function.

John Lukacs
John Lukacs
26,806 Points

function returnValue(str){ return str; } var echo = returnValue("hype");