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

Jose Mendoza
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Jose Mendoza
UX Design Techdegree Graduate 19,788 Points

I have no idea how to set "var echo" to the "returnValue"

I have been stuck on this challenge for a while now and I need some help. Step 2 is asking me to set the variable "echo" to the returned results from "returnValue". I honestly don't understand how all of this works. Could anyone elaborate on what's going on here? What am I missing?

script.js
function returnValue( name ) {
  return name;
  var echo = returnValue;
}

returnValue('Jose');

2 Answers

Hi Jose Mendoza, you are really close on this one. only one thing to change, and that is the var echo needs to be out side of the function. and you need to call the function as well. like so

var echo = returnValue("Jose");

what is happing here is you are taking the return value of the function and placing it into the var echo. You were close you had the var echo inside the function and called the function by itself not in the var echo.

Jose Mendoza
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Jose Mendoza
UX Design Techdegree Graduate 19,788 Points

Oh! that makes a lot more sense. I wasn't too sure why I was putting the variable echo inside of my function. Thanks again!

No worries, any time!

Gianmarco Mazzoran
Gianmarco Mazzoran
22,076 Points

Hi,

the second step of this challenge ask you to create a variable called "echo" after the function, which means that need to be created outside the function returnValue. Then set the value of the variable "echo" to be the results from calling the returnValue function, that's basically said that you have to simply call the function and last they recommend that you pass the parameter in a string format.

Like this:

function returnValue(name) {
  return name;
}

var echo = returnValue('Jose');