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

Why does adding my variable 'echo' cause Challenge Task 1 to fail?

I'm working through the challenge tasks and task one- create a function called returnValue - was passed with the code:

function returnValue(value){

return value;
}

but when I move to task 2 and add :

returnValue("My Argument");
var echo = value;

The code checker claims that task 1 is no longer working. Simply commenting out my last 2 lines and rechecking the work makes Task 1 pass again.

Can anyone help explain how I'm breaking the function by calling it and storing the value in a variable? Thanks!

1 Answer

Hugo Paz
Hugo Paz
15,622 Points

Hi Weston,

I edited your code to make it more legible, click on edit post to see how i did it.

Value just exists inside the function scope. To get that value you need to assign a variable to the result of that function, like so:

var echo = returnValue("My Argument");