Welcome to the Treehouse Community
The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Alfredo Galvez
4,949 PointsAssign `message` a value in the conditional statment only.
I get the bummer alert, but I believe I did everything the way it was supposed to. Correct me if im wrong please!
const isAdmin = true;
const isStudent = false;
let message;
if (isAdmin){
let message = "Welcome admin.";
}
2 Answers

Joseph Yhu
PHP Development Techdegree Graduate 48,500 PointsRemove let
inside the conditional.

Alfredo Galvez
4,949 PointsAlright! thank you both for helping me out! On another matter, why removing the let makes it work? Is it because trying to assign the value to the variable using let would be like creating a new one? Sorry if I'm being silly here.

Jason Larson
7,955 PointsYes. The first let message;
statement defines the variable with script-level scope. When you use let message = "Welcome admin.";
inside the if statement, you are declaring a new variable that only exists until the if statement is done, so if you tried to use the message variable afterwards (like with a console.log(message);
, the output would be undefined
rather than the expected message because the first message variable is initialized to undefined
when it is created, and then it is never updated. By removing the let
from inside the conditional, you are then assigning the value "Welcome admin." to the variable message that you created with the let message;
statement.
Jason Larson
7,955 PointsJason Larson
7,955 PointsIn addition to removing the let inside the conditional, also be sure to remove the period, as that will cause this task to fail.