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
Justin Rose
13,601 PointsScope and Hoisting Confusion in Javascript
Totally Stuck on Scope, Hoisting and shadowing. can any body clear up the confusion with this problem? that would be awesome
function elevatorCloseButton(pushed) {
if (pushed) {
var status = "I'll close when I'm ready.";
}
}
elevatorCloseButton(true);
1 Answer
Hugo Paz
15,622 PointsHi Justin,
You need to declare the variable at the start of the function and then set it within the condition.
function elevatorCloseButton(pushed) {
var status;
if (pushed) {
status = "I'll close when I'm ready.";
}
}
elevatorCloseButton(true);
Robert Richey
Courses Plus Student 16,352 PointsRobert Richey
Courses Plus Student 16,352 PointsEdit: added markdown for JavaScript
Hi Justin,
Can you post a link to the challenge you're working on?