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 trialDylan Moberg
5,352 PointsI am having trouble with the JavaScript foundations variables code challenge
The question asks me to "Alter the 'elevatorCloseButton' function to follow the best practices in declaring variables within the scope of the function." After moving the var status to under the function and assigning status to "I'll close when I'm ready." It still asks me to "assign the status variable in the if statement" what am I doing wrong?
eck
43,038 PointsIf you post your code we can help you figure out what is amiss :D
Dylan Moberg
5,352 PointsThis is the original code of the challenge, question "Alter the 'elevatorCloseButton' function to follow the best practices in declaring variables within the scope of the function."
<!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) {
if (pushed) {
var status = "I'll close when I'm ready.";
}
}
elevatorCloseButton(true);
</script>
</body> </html>
Ken Alger
Treehouse TeacherDylan;
Yes, but what have you tried? I can post the code to solve the task, but would love to see what you have tried.
Ken
Dylan Moberg
5,352 PointsThis is my code.
<!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.";
}
}
elevatorCloseButton(true);
</script>
</body>
</html>
Ken Alger
Treehouse TeacherEdited for markup.
2 Answers
Ken Alger
Treehouse TeacherDylan;
Perfect, thanks for posting your code.
The challenge tasks asks us to:
Alter the 'elevatorCloseButton' function to follow the best practices in declaring variables within the scope of the function.
You don't want to define the variable initially, just declare it, so the code snippet would look like:
// Hoisting Code Challenge
<script>
function elevatorCloseButton(pushed) {
var status;
if (pushed) {
status = "I'll close when I'm ready.";
}
}
elevatorCloseButton(true);
</script>
Happy coding, Ken
Dylan Moberg
5,352 PointsThat makes a lot more sense, thank you for responding so quickly!
Ken Alger
Treehouse TeacherPleased it worked out and that it helped.
Happy coding and welcome to Treehouse!
Ken
Kez Khou
3,903 PointsHmmm... interesting, thank you much Ken Alger ! I was having issues with that particular hoisting challenge as well. I didn't have the same mark up issues as Dylan Moberg , but your clarification definitely made sense and worked for me as well.
Ken Alger
Treehouse TeacherKen Alger
Treehouse TeacherDylan;
Can you post the code you are using? It sounds like you are very close, but without seeing the exact code it is difficult to diagnose the issue.
Thanks,
Ken