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 Foundations Variables Hoisting

Alter the 'elevatorCloseButton' function to follow the best practices in declaring variables within the scope of the fun

Not understanding how to alter the function

1 Answer

geoffrey
geoffrey
28,736 Points

You just have to declare the variable just after the conditional if statement with the var keyword. This way you'll be sure the scope of the variable is going to be inside the function If I remember well. Then as you are in the same scope, you can simply assign the string value you want if the condition is true, if(pushed).

After

function elevatorCloseButton(pushed) {
        var status="";
        if (pushed) {
            status = "I'll close when I'm ready.";
        }

    }

    elevatorCloseButton(true);
Gerard Weppler
Gerard Weppler
4,357 Points

Thank you Geoffrey, I was stuck on this question. I guess I should re-watch this video again because I was not fully understanding.