Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript JavaScript Basics (Retired) Creating Reusable Code with Functions Passing an Argument to a Function

Tatiane Lima
Tatiane Lima
6,738 Points

what is wrong in my code

/* THIS IS 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. */

function returnValue(singleArgument) {
  var echo = singleArgument;
  return echo;

Mod note: Added formatting to the javascript code so we could see more easily

4 Answers

Jonathan Grieve
Jonathan Grieve
Treehouse Moderator 90,705 Points

Let's walk through what the challenge is asking for.

First, create the function block

function returnValue(argument) {

 return argument;

So this function will take a string as a value and expects a return statement to return the value back to the function. Use the parameter as the return value.

Having done this you then declare a variable, outside of the function. Then assign a function call to the variable.

function returnValue(arg) {

  return arg;

var echo = returnValue("String");

Where the string is the argument that is passed into the function.

Good luck.

Steven Parker
Steven Parker
215,940 Points

:point_right: The challenge says "After your newly created returnValue function..."

You should leave the function as it was in the previous task step. Then create the echo variable below the function and not inside it.

You will assign the value to echo by calling the function, something like this:

let echo = returnValue("some string");
Tatiane Lima
Tatiane Lima
6,738 Points

I already know the correct answer:

function returnValue(singleArgument) { return singleArgument; } var echo = returnValue("example");

But the message of error of this question wasn't helpful :(