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

matt lucas
matt lucas
3,719 Points

Code Challenge: Hoisting | Having trouble declaring the variable

I understand that the variables need to be declared at the top, before the function. Is pushed the variable that needs to be declared? I feel like I've tried everything else.

The code begins here:

function elevatorCloseButton(pushed) {

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

}

Thanks for any help. If there's a better explanation for scope and hoisting than the deep dive video a link would be really appreciated. It seems so obvious but I clearly don't get it.

4 Answers

Shannon Yeh
Shannon Yeh
8,987 Points

okay I figured it out after watching the video TWICE.

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

}

elevatorCloseButton(true);

that is how you solve this problem!

Shannon Yeh
Shannon Yeh
8,987 Points

i am really stuck on this as well. lost!

Thanks a lot, Shannon. :)

Shannon Yeh
Shannon Yeh
8,987 Points

no problem for some of these you REALLy have to keep watching the video. lol

Eric Ewers
Eric Ewers
13,976 Points

Thanks, it took me like 15 minutes to figure this one out!