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 trialAdama Sy
7,076 Pointschallenge code hoisting I dont understand what they asking witht he first question
Alter the elevator....
really I dont get it anyone online to help
4 Answers
Philip Cox
14,818 PointsJavascript Hoisting explains how JS with automatically bring your variables above other code for cache purposes. This may end up effecting your scope and shadowing of variables. or accidentally rewriting a variable.
You will have to elaborate on your question please.
Adama Sy
7,076 Points<!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>
Adama Sy
7,076 PointsAlter the 'elevatorCloseButton' function to follow the best practices in declaring variables within the scope of the function.
Joshua Russo
10,037 PointsI've tried all different combinations and cannot get this answer. Where do we define the variable? I would think it needs to be defined before the function but also called after the if statement in the function as well.. Any help is appreciated!
Ben Junya
12,365 PointsBen Junya
12,365 PointsI second Phillip Cox's answer.
Also, we have no idea what you're asking. What's confusing about it? Phillip did a pretty good job explaining hoisting.
Adama Sy
7,076 PointsAdama Sy
7,076 PointsI did it I simply had to move var status on top to declare it. then had status=""; after the if.
thanks