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

I'm not sure of what is being asked

The Challege question is "Alter the 'elevatorCloseButton' function to follow the best practices in declaring variables within the scope of the function".

Not sure how to answer this question:

    <script>

    function elevatorCloseButton(pushed) {

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

    }

    elevatorCloseButton(true);

    </script>

3 Answers

Tobiasz Gala
seal-mask
.a{fill-rule:evenodd;}techdegree
Tobiasz Gala
Full Stack JavaScript Techdegree Student 23,529 Points
function elevatorCloseButton(pushed) {
var status;
        if (pushed) {
            status = "I'll close when I'm ready.";
        }

    }

    elevatorCloseButton(true);

I think this is an answer. You should always declare variable at the beginning and set value later when you need it.

Jason Taylor
Jason Taylor
3,059 Points

Right before the if statement, try adding var status;

Thank you guys. I appreciate it