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 trialNicole Raglin
2,522 PointsVar-Hoist Quiz
What am I doing wrong???
<!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) {
status = "I'll close when I'm ready.";
console.log("status in if (){}", status);
}
}
elevatorCloseButton(true);
</script>
</body> </html>
Nicole Raglin
2,522 PointsHi Mike. It is a challenge and part of a challenge!
http://teamtreehouse.com/library/hoisting
I cannot seem to execute it properly...but I did just notice that I skipped a whole section of Java!
:)
Mike Bronner
16,395 PointsJust a quick comment, and it's not meant to be persnickety. Don't confuse Java with JavaScript. They actually have nothing at all to do with each other. :) I see those two terms confused a lot, and using them incorrectly may cause more confusion.
Nicole Raglin
2,522 PointsI don't think you are being persnickety. Your correction is correct and taken to heart. I am still getting the error
You should assign the 'status' in the if statement.
I am a little clueless as I missed the whole basics section. I am doing it over.
1 Answer
Mike Bronner
16,395 PointsOk, this wasn't too hard, although it might be a bit confusing as to what they were asking.
They ask you to declare the variable in the function following best practice, which says to declare variables toward the top of the function, rather than interspersed.
Really the only thing you need to do is declare the status variable right after the function opens, and remove the declaration (not the assignment) from within the if statement.
Let me know if that gets you on track, or if it is still unclear. If so, I can help you further with some pseudo-code for the function. :)
~Mike
Nicole Raglin
2,522 PointsI don't think you are being persnickety. Your correction is correct and taken to heart. I am still getting the error
You should assign the 'status' in the if statement.
I am a little clueless as I missed the whole basics section. I am doing it over.
Mike Bronner
16,395 PointsIn your code above you are declaring and assigning the variable status a value. Don't assign it anything when you declare it (that's not necessarily best practice, just this scenario). After that it should work.
Nicole Raglin
2,522 PointsFinally! Thank you! You were a huge help! Now I am going to go over JavaScript again...from the beginning this time! Thank you!!!
Mike Bronner
16,395 PointsThat's great to hear! :)
Mike Bronner
16,395 PointsMike Bronner
16,395 PointsPlease explain in more detail as to what this code is or isn't doing that is contra to your expectations. Also, if it is part of a challenge, please link to the challenge.