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

Deep Dive Javascript Variables last Challenge Question

Alter the 'elevatorCloseButton' function to follow the best practises in declaring variables within the scope of the function.

The code is like this:

function elevatorCloseButton(pushed) {

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

}

elevatorCloseButton(true);  

And I made the following:

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

}

elevatorCloseButton(true)

It says "You need to declare 'status' at the top of the 'elevatorCloseButton"

1 Answer

Andrew Chalkley
STAFF
Andrew Chalkley
Treehouse Guest Teacher

Hi there,

You just need to declare var status at the top. However the assignment of `"I'll close when I'm ready." sill needs to be in the conditional statement.

Hope that helps

Regards
Andrew

Hi Andrew

Thank you for your reply.

May I need some little more help.

I did declare var status at the top. What I don't get is how excatly to assign the "status" iin the conditional statement(if).

Regards George

Andrew Chalkley
Andrew Chalkley
Treehouse Guest Teacher

No worries :)

var status; would just declare it.

status = "some value" would assign a value to the status variable.

You are right I had just to declare it and then assign in the conditional statement the "value"

Again thank you.