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 Review: Scope

Julie Ann DelaPena
Julie Ann DelaPena
3,716 Points

var counter = 0; function doStuff( ) { return counter = 10; }

var counter = 0; function doStuff( ) {

return _____________ counter = 10; }

3 Answers

Benjamin Larson
Benjamin Larson
34,055 Points

Hi Julie,

It's looking for the "var" keyword:

return var counter = 10;

The question asked : Finish the code below so that the variable counter inside the function is only accessible inside that function.

Adding the "var" keyword declares the variable within the scope of the function only, so that it will not affect the value of any variable named counter outside of that function, or in another function. Leaving out the "var" keyword would make it a global variable.

Joseph Vincent Trajano
Joseph Vincent Trajano
1,933 Points

i still don't get it can anyone help me with this

var