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
George Drakoglou
7,969 PointsDeep Dive Javascript Variables last Challenge Question
Alter the 'elevatorCloseButton' function to follow the best practises in declaring variables within the scope of the function.
The code is like this:
function elevatorCloseButton(pushed) {
if (pushed) {
var status = "I'll close when I'm ready.";
}
}
elevatorCloseButton(true);
And I made the following:
function elevatorCloseButton(pushed) {
var status = "I'll close when I'm ready.";
if (pushed) {
console.log(status);
}
}
elevatorCloseButton(true)
It says "You need to declare 'status' at the top of the 'elevatorCloseButton"
1 Answer
Andrew Chalkley
Treehouse Guest TeacherHi there,
You just need to declare var status at the top. However the assignment of `"I'll close when I'm ready." sill needs to be in the conditional statement.
Hope that helps
Regards
Andrew
George Drakoglou
7,969 PointsGeorge Drakoglou
7,969 PointsHi Andrew
Thank you for your reply.
May I need some little more help.
I did declare var status at the top. What I don't get is how excatly to assign the "status" iin the conditional statement(if).
Regards George
Andrew Chalkley
Treehouse Guest TeacherAndrew Chalkley
Treehouse Guest TeacherNo worries :)
var status;would just declare it.status = "some value"would assign a value to thestatusvariable.George Drakoglou
7,969 PointsGeorge Drakoglou
7,969 PointsYou are right I had just to declare it and then assign in the conditional statement the "value"
Again thank you.
Andrew Chalkley
Treehouse Guest TeacherAndrew Chalkley
Treehouse Guest TeacherNo worries! Keep up the good work!