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 trialRobert Roath
1,072 Pointsissue on create a conditional statement exercise.
I have put the message statement both inside and outside the if. It is passing on my end any ideas?
const isAdmin = true;
const isStudent = false;
if (isAdmin == true) {
const message = ("Welcome admin");
console.log( message );
}
2 Answers
Steven Parker
231,269 PointsYou need to leave the declaration of "message" as it was provided initially in the global scope.
By moving the declaration into the conditional block, it is no longer visible from the global scope and the challenge cannot see that it was assigned (or even exists).
Put the original declaration back and just assign it in your code.
Ashley Jennings
3,087 PointsThis is how your code should look.
const isAdmin = false; const isStudent = true; let message;
if ( isAdmin ) { message = 'Welcome admin'; }
Robert Roath
1,072 PointsRobert Roath
1,072 PointsHere is the exercise: https://teamtreehouse.com/community/issue-on-create-a-conditional-statement-exercise
Have tried both of these:: const isAdmin = true; const isStudent = false; let message = ("Welcome admin");
if (isAdmin == true ) { console.log( message); }
and const isAdmin = true; const isStudent = false;
if (isAdmin == true ) { let message = ("Welcome admin"); console.log( message); }
both are passing Welcome admin for me when testing it in node <script>.. any idea why the exercise is failing?