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

Muaadh Fadi
Muaadh Fadi
1,737 Points

Return Value

Can someone help me out with this? It requests me to return the argument that's passes in to the function.

script.js
function returnValue(width, length, unit) {
  var area = width * length;
  return area + " " + unit;
}
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

Kyle Knapp
Kyle Knapp
21,526 Points

The challenge expects you to return one of the parameters being passed into your function. In this case you are returning area, which is a variable that you defined in the function scope, not a parameter.

In your function, width, length and unit are your parameters, so you can simply return any one of those to complete the challenge.

function returnValue(width, length, unit) {
  /* This line of code is not needed for this challenge.
  var area = width * length;  */
  return width;
}
Muaadh Fadi
Muaadh Fadi
1,737 Points

Managed to figure it out. Many thanks for the response anyway.