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!

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

Java Script Challenge :function elevatorCloseButton

why is it telling me to call the status in the if statement?


<!DOCTYPE html> <html lang="en"> <head> <title> JavaScript Foundations: Variables</title> <style> html { background: #FAFAFA; font-family: sans-serif; } </style> </head> <body> <h1>JavaScript Foundations</h1> <h2>Variables: Hoisting</h2>


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




</body> </html>

i'm at the same spot and also would like to know the answer....

1 Answer

Hi Susan,

The code they are looking for is this:

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

Even though the code would function the same with the var keyword inside the if statement (the way it is when you start the challenge), it's a best practice to define all the variables that you're going to use inside the function at the top - even before you've used them.

It makes it easier to the read code if you can see all the variables that are going to be in play in the function right at the top.

Thank you