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

I've been stumped on this for hours! Please tell me what i did wrong. Thanks

I appreciate the assistance

script.js
function returnValue(length){
  var echo = length;
  return  length;
}
returnValue('50');
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>

4 Answers

David Evans
David Evans
10,490 Points

Hi Brian,

You are so close! Try re-reading the question.

After your newly created returnValue function, create a new variable named echo. Set the value of echo to be the results from calling the returnValue function. When you call the returnValue function, make sure to pass in any string you'd like for the parameter.

It states AFTER your newly created returnValue function.

This means its looking for you to create your echo variable outside the function.

function returnValue(length){
  return length;
}

var echo = returnValue('test string');
Steven Parker
Steven Parker
229,644 Points

The function you create in task 1 should remain as-is for task 2. The task 2 code will be added after the function and not inside it.

You just need to create and assign the "echo" variable by calling your function. So task 2 can be a one-liner.

I'll bet you can do it now without a code spoiler.

Andrew Hickman
seal-mask
.a{fill-rule:evenodd;}techdegree
Andrew Hickman
Full Stack JavaScript Techdegree Student 10,013 Points

Hey Brian! The challenge asks you to create a variable (echo) in the global scope AFTER the returnValue function. var echo should equal the returned value of the function:

function returnValue(length){
  return  length;
}
var echo = returnValue('50');

thanks everyone! i got it now