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

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!