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

Need help with this task

I don't understand this part of the challenge. I have tried this many ways with no success. Anyone have any pointers?

script.js
function returnValue(width) {
  return width;
}
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

Gianmarco Mazzoran
Gianmarco Mazzoran
22,076 Points

Hi,

the challenge is asking you to store your new function inside a variable named echo. And then pass a string as value of the function.

Here's what you need:

script.js
function returnValue(arg) {
    return arg;
}

var echo = returnValue("your string");

Thank you so much. I was making this much more difficult than it needed to be.

Carlos Federico Puebla Larregle
Carlos Federico Puebla Larregle
21,074 Points

Like the task says "This isn't that useful of a function" it's just for you to understand how you can pass an argument to a function. In the next step of the task it asks you to assign the returned value from the function to a newly created variable called "echo". Like this:

function returnValue(width) {
  return width;
}

var echo = returnValue("Anything");

I hope that helps you a little bit.