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 trialLindsey Davis
2,301 Pointselevatorclosebutton
I'm not sure what I a doing incorrectly and how to fix this. Does anyone know what I'm doing wrong?
function elevatorCloseButton(pushed) {
var = status;
if (pushed) {
var = status;
status = "I'll close when I'm ready.";
}
}
<!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;
if (pushed) {
var = status;
status = "I'll close when I'm ready.";
}
}
elevatorCloseButton(true);
</script>
</body>
</html>
2 Answers
Ken Alger
Treehouse TeacherLindsey;
A couple of things.
- You have
var = status;
, it should bevar status;
- You have that declaration twice. Once outside the
if
statement (Good). Once inside theif
statement (not a best practice).
Your code, therefore, needs to look something like:
function elevatorCloseButton(pushed) {
var status;
if (pushed) {
status = "I'll close when I'm ready.";
}
}
elevatorCloseButton(true);
Does that make any sense?
Happy coding,
Ken
Michael De Marre
14,198 PointsHi Lindsey,
The problem is that you've declared the variable status twice using the var command. Remove the second declaration and leave the new status value:
function elevatorCloseButton(pushed) {
var status;
if (pushed) {
status = "I'll close when I'm ready."
}
}