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 trialSusan Trachsel
5,489 PointsJava Script Challenge :function elevatorCloseButton
why is it telling me to call the status in the if statement?
\\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) {
var status = "I'll close when I'm ready.";
if (pushed) {
console.log(status);
}
}
elevatorCloseButton(true);
</script>
</body> </html>
1 Answer
Mac Eisenberg
3,653 PointsHi Susan,
The code they are looking for is this:
function elevatorCloseButton(pushed) {
var status;
if (pushed) {
status = "I'll close when I'm ready.";
}
}
Even though the code would function the same with the var keyword inside the if statement (the way it is when you start the challenge), it's a best practice to define all the variables that you're going to use inside the function at the top - even before you've used them.
It makes it easier to the read code if you can see all the variables that are going to be in play in the function right at the top.
elschnuppero
Courses Plus Student 2,380 PointsThank you
elschnuppero
Courses Plus Student 2,380 Pointselschnuppero
Courses Plus Student 2,380 Pointsi'm at the same spot and also would like to know the answer....