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

Ajla N
Ajla N
17,674 Points

Code Challenge: Hoisting

I can't figure out what I'm doing wrong, I've tried to do this challenge so many times now!

This is my code so far:

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

}

elevatorCloseButton(true);

It keeps telling me "You should assign the 'status' in the if statement". The only way I know how is to use the console.log, that's what was used in the video. I just can't figure this one out!

Any help would be really appreciated! :)

3 Answers

Hey Ajla N

You have to declare the variable status in the beginning of your function. Once the variable is declared, you are able to use it in the if section of your function.

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

}

elevatorCloseButton(true);
Ajla N
Ajla N
17,674 Points

Thank you sooo so much!!! :D

You're welcome, glad to help!

Michael Maloof
Michael Maloof
4,581 Points

Wow thank you so much! I seriously looked through the forums for an hour and no one else could figure it out!