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

Val Ki
Val Ki
1,997 Points

Please help!

I keep running into an error when I run this code. Please help.

script.js
function returnValue(age) {
 var echo = 'hi there'; 
  return age;

}

returnValue('15');
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>
Val Ki
Val Ki
1,997 Points

I keep running into this:

Bummer! Hmmm. It doesn't look like you're storing the returned value in the echo variable.

1 Answer

Rich Donnellan
MOD
Rich Donnellan
Treehouse Moderator 27,708 Points

Hi, Val!

You're so close! It's all in the wording:

After your newly created returnValue function, create a new variable named echo.

Extract your variable declaration to be outside of the function, and assign your last line to it (e.g. var someVar = functionCall(arg);). This effectively stores the return value in your variable for later use.

Hope this hint helps!

Val Ki
Val Ki
1,997 Points

Hi Rich,

I think I am trying your way but I'm still getting an error. Could you write out the code?

Rich Donnellan
Rich Donnellan
Treehouse Moderator 27,708 Points

Sure thing.

Spoiler

function returnValue(age) {
  return age;
}

var echo = returnValue('15');