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

matt lucas
3,719 PointsCode Challenge: Hoisting | Having trouble declaring the variable
I understand that the variables need to be declared at the top, before the function. Is pushed the variable that needs to be declared? I feel like I've tried everything else.
The code begins here:
function elevatorCloseButton(pushed) {
if (pushed) {
var status = "I'll close when I'm ready.";
}
}
Thanks for any help. If there's a better explanation for scope and hoisting than the deep dive video a link would be really appreciated. It seems so obvious but I clearly don't get it.
4 Answers

Shannon Yeh
8,987 Pointsokay I figured it out after watching the video TWICE.
function elevatorCloseButton(pushed) {
var status;
if (pushed) {
status = "I'll close when I'm ready.";
}
}
elevatorCloseButton(true);
that is how you solve this problem!

Shannon Yeh
8,987 Pointsi am really stuck on this as well. lost!

Liudmyla Ignatova
100 PointsThanks a lot, Shannon. :)

Shannon Yeh
8,987 Pointsno problem for some of these you REALLy have to keep watching the video. lol

Eric Ewers
13,976 PointsThanks, it took me like 15 minutes to figure this one out!
João Arruda
5,992 PointsJoão Arruda
5,992 PointsThanks Shannon :)
Ryan Drake
12,587 PointsRyan Drake
12,587 PointsThank you Shannon! Appreciate it :)
Jeremy Canela
Full Stack JavaScript Techdegree Graduate 30,766 PointsJeremy Canela
Full Stack JavaScript Techdegree Graduate 30,766 PointsThanks