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 Giving Information to Functions

Carleen Hall
seal-mask
.a{fill-rule:evenodd;}techdegree
Carleen Hall
Front End Web Development Techdegree Student 3,158 Points

Giving information to functions

Giving Information to a function. I am completely stumped on this one. Can someone explain.? Thanks

Challenge Task 2 of 2 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. 

The function will accept the string you pass to it and return it back (using the return statement). Then your echo variable will be set with what is returned, the results

Here is my code.

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

Greetings Carleen Hall,

I'd gladly assist, but could you first explain what you have tried and what, in particular, you find difficult or confusing? It will help me help you :)

Carleen Hall
seal-mask
.a{fill-rule:evenodd;}techdegree
Carleen Hall
Front End Web Development Techdegree Student 3,158 Points

I don't understand "setting the value of echo to be the results from calling the returnValue function". I feel I understood everything when watching Dave's video. But now it's clear I don't understand. I watch the video several times trying to make sense of this challenge but it does not help. Hopefully, you understand what I am trying to say. :)

2 Answers

Jonathan Grieve
MOD
Jonathan Grieve
Treehouse Moderator 91,252 Points

Hi Carleen.

What you want to do here is "call" the function. That is invoke the function do make it do something. In this case you're returning a value.

   function returnValue(Nike){

   return Nike;
}

The value it takes is determined when you make the function call and this comes after the function itself.

var echo = returnValue("Nike"); 

So this is where you declare you variable. you then assign the function call to it and see between the parentheses... where you put your Nike parameter. You can then put any string you like in there as the value.

And the full code...

   function returnValue(Nike){    
      return Nike;
}

var echo = returnValue("Nike"); 
Carleen Hall
seal-mask
.a{fill-rule:evenodd;}techdegree
Carleen Hall
Front End Web Development Techdegree Student 3,158 Points

Thanks, Jonathan, I think where my confusions lie is in thinking that return is used to end the function, therefore I thought that the "var echo" should be the last thing in the programme. Eventually I will get it.