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

Jason Larkin
Jason Larkin
13,970 Points

Hoisted Variables Problem

I am finishing up a unit on hoisted variables, but the prompt that the challenge gives me, that the "status" should be within the elevatorCloseButton seems to have nothing whatever to do with the preceding video lesson. Can anyone help please?

Here is the HTML? js :

    function elevatorCloseButton(pushed) {

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

    }

    elevatorCloseButton(true);

    </script>
Jason Larkin
Jason Larkin
13,970 Points

Thank you but now it says that I have to declare 'status' above the 'elevatorCloseButton' , whatever that means. I really wish I could figure this out but the video doesn't cover any of this.

Jason Larkin
Jason Larkin
13,970 Points

It's in the JavaScript Foundations course- Variables.

2 Answers

Sage Elliott
Sage Elliott
30,003 Points

Try declaring your variable before the if statement.

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

    }

    elevatorCloseButton(true);
Sage Elliott
Sage Elliott
30,003 Points

This passes the code challenge for me. I just confirmed. Did you make any other changes?

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

    }

    elevatorCloseButton(true);
Sage Elliott
Sage Elliott
30,003 Points

You can try refreshing incase some other code was edited.