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

Justin Bigos
Justin Bigos
3,828 Points

passing argument to function challenge

I am completely stuck on this. I finish the first part with function returnValue ( my name) { return myname; } i move to part 2 and no matter what I enter it gives me a constant stream of error messages. I didn't include any code because I am convinced i am just completely lost on this. For some reason this problem is making no sense to me, i feel very frustrated and wonder how I can be so lost after getting this far understanding everything really well. Any help or examples would help. ugggg.

Justin

6 Answers

Jason Anders
MOD
Jason Anders
Treehouse Moderator 145,860 Points

So the first part you created the named function that just returns the argument passed into the function when called. I used the variable 'name.'

var returnValue = function(name) {
  return name;
};

The second part of the challenge wants you to call the function with a string passed in as the argument. To call a function is just typing in the function name and the argument(s): `returnValue("Justin Bigos");'

The specific part of the challenge wants you to create a variable 'echo' where the return (result) of the function call is stored. The function is designed to just return what was passed into it, so the variable will hold your name. To do this you just assign the function call to a new variable 'echo'

var returnValue = function(name) {
  return name;
}; //creates the function

var echo = returnValue("Justin Bigos"); //stores the 'return' of the function in the var echo

I hope this make sense. Keep coding. :)

The solution provided by the respected Moderator - Jason - is very detailed and helpful. However, the part that got me confused was the first one. In the task, it's been said: "Create a function named returnValue that accepts a single argument (you can name it anything), then immediately returns that argument."

So, we are creating the exact function, literally, not a variable, as it was suggested:

function returnValue(name) {
  return name;
}

It helped me pass the task. Just to make it clear for others. Thanks Jason, you helped me out with this also.

Joshua Bressack
Joshua Bressack
4,538 Points

I had run into the same trouble. Thanks guys for being there.

Jason Anders
MOD
Jason Anders
Treehouse Moderator 145,860 Points

Hi Justin, What is "part 2" that you are referring to? The 'maxValue' challenge?

Justin Bigos
Justin Bigos
3,828 Points

The 2nd part of the passing functions' code challenge, where you create the Echo variable. That's the part I am stuck on.

Justin Bigos
Justin Bigos
3,828 Points

Thank you that helped. I was making the dumbest error and sticking the var echo in the curly brackets. uugg such a simple oversight caused me so much trouble. I thought I was losing it. JB

Jason Anders
Jason Anders
Treehouse Moderator 145,860 Points

Hey Justin, glad that helped. There is no such thing as a 'dumb' mistake. Even the best coder will make the simplest mistake. Often it is a fresh set of eyes, and as long as we all help each other... all should be well. :)

Christina Perez
Christina Perez
2,605 Points

This was really helpful. I was totally missing a step and banging my head against a wall.