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

cant figure this one out

I need to store the returned value in a variable

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

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

victor cooper
victor cooper
6,436 Points

In a function everything after a return is ignored, the variable or value that is after the return command will be the value that the function returns.

so to store a function return in a variable you need to create a function

function myFunc (value) {
  return value;
}

then you need to create a variable that will store the returned value from the function

var myVariable = myFunc('nick');
Steve holcomb
Steve holcomb
1,931 Points

Yeah this still isnt working. Im not sure what im doing wrong. Where do I put the new varible at? I was thinking it would be outside the function.