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

Greg Schudel
Greg Schudel
4,090 Points

I am unsure of what is being asked.

I am unclear on what is being asked here. What is the correct answer? I have made the following code only to be told that my "task 1 is now not working."

function returnValue(nameItAnything) { var echo = return (nameItAnything); }

script.js
function returnValue (nameItAnything){

  return(nameItAnything);

}
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>
David Bath
David Bath
25,940 Points

The echo variable should be created outside the returnValue function, and needs to pass a string to that function:

var echo = returnValue("something");

The returnValue() function will just pass back the value you sent it (in my example "something").

1 Answer

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

For this particular challenge the index.html isn't needed or even referenced. They simply are challenging your ability to define a function, pass it an argument, and then return something and assign it to a variable. See my code for clarification:

function returnValue (x) {
  return x;
}

var echo = returnValue("Hi there!  This can be anything!");

Here I make a function called returnValue and it takes an argument named x. I then immediately return that value. This will not be the case in most functions. Most functions will want you to do something with that information.

Then I make a variable named echo as required by the challenge. I call/invoke/execute the function and send it the string"Hi there! This can be anything". At this point in the function x becomes that string which it then returns. The resulting string is assigned to echo.