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

Philip Valentini
Philip Valentini
3,448 Points

Not sure what they questions is ...seems unclear.

Please advise on how to answer the second part of this question

script.js
function returnValue(width) {
  var echo = 20;
  return width;
}
returnValue("hello");
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>
Aaron Glaesemann
Aaron Glaesemann
11,303 Points

Hi Philip!

They're just requesting that you know how to structure a function. In the challenge this functions does nothing more than takes the parameter and returns it back to you.

MDN provides and excellent resource on how to create a function. If you'd like for me to provide an example I'd be happy to help. Otherwise you can look at examples provided by the Mozilla Dev Network here: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions

Philip Valentini
Philip Valentini
3,448 Points

Perhaps you can please provide me with me with an example in the context of this exercise in the code challenge.

Aaron Glaesemann
Aaron Glaesemann
11,303 Points

This code will work. If you have any questions on why it works please let me know, I'd be happy to explain.

function returnValue(anything) {
  return anything
}

var echo = returnValue('string');

So in your example:

function returnValue(width) {
  var echo = 20;
  return width;
}

It really only needs to appear as:

function returnValue(width) {
  return width
}

var echo = returnValue('whatever');

I noticed you were probably having issues with Challenge 2/2 not 1/2. So I updated my answer to reflect that.

1 Answer

Philip Valentini
Philip Valentini
3,448 Points

Thanks Aaron, that part I got correct, but its the second part of the question that i was stuck on...they are asking for the var echo to hold the retuned value of the function which I touch would be "width"...but it keep s saying to put the return value as the value of echo...I was confused a bit.

Thank you for your help!

Aaron Glaesemann
Aaron Glaesemann
11,303 Points

Ahhh. Yeah, my bad. I updated my original answer to reflect that. Take a look at that again. Basically, you had everything correct just that it wasn't being instanced in a variable.

Philip Valentini
Philip Valentini
3,448 Points

Thanks Aaron,

I see you added the second part of the question now....Much appreciated!.