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 JavaScript Foundations Variables Hoisting

Adam Duffield
Adam Duffield
30,494 Points

Assign the status in the IF statement - Javascript Foundations

Hey, Little stuck on this Javascript Challenge, heres my code below:

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

}

elevatorCloseButton(true);

It's telling me I need to assign the status in the IF statement which I think I'm doing. Any tips how to fix this?

Thanks,

Adam

3 Answers

Ruben Leija
Ruben Leija
4,051 Points

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

}

elevatorCloseButton(true);

Tim Knight
Tim Knight
28,888 Points

Maybe it's getting confused from your var status; setting above the conditional? I tried this (adding my alert statement to confirm it's working).

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

elevatorCloseButton(true);
Adam Duffield
Adam Duffield
30,494 Points

Thankyou guys! I do love treehouse so far, the support on the challenges is lacking but that's why you guys on this forum are making a massive difference for me!