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

Help with JavaScript

I've been having some difficulty understanding what's going on in this particular course dealing with JavaScript. I really have no clue as to what I'm supposed to write in this coding challenge.

If anybody could help with this I would appreciate it so much!

index.html
<!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>

    <script>

    function elevatorCloseButton(pushed) {

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

    }

    elevatorCloseButton(true);

    </script>
  </body>
</html>

Here is the challenge.

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

1 Answer

Alex Heil
Alex Heil
53,547 Points

hey Ira Salem , from the previous videos we learned that a best practice is to first define the variable and then later assign a value when needed, so it would look like this:

function elevatorCloseButton(pushed) {

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

hope that helps and have a nice day ;)

Got it. Thanks.

Don't know my brain has been so scrambled when it comes to javascript.

Alex Heil
Alex Heil
53,547 Points

no worries, JS is not my best friend as well ;) but I can highly recommend the new JS course called Javascript Basics teached by Dave McFarland , this course is really fun and well made, much better than the old foundations course that you're currently going through.

Thanks. I'll definitely take a look at it. The only real reason I'm still in this particular course is for one I'm sure I'll need it someday. Two it's apart of the track I'm currently in and I'd hate not to complete it. I've just been sort of powering through this one course. I can say even though the course I'm in is pretty dry as far as "funness" go, it's still WAY better than reading about it on your own aimlessly going nowhere. lol I'll definitely look at the course you recommended though.

Thanks,