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 trial

JavaScript JavaScript Basics Making Decisions in Your Code with Conditional Statements Write an 'if' Statement

Robert Roath
Robert Roath
1,072 Points

issue 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?

script.js
const isAdmin = true;
const isStudent = false;

if (isAdmin == true) { 
  const message = ("Welcome admin");
  console.log( message );
}
Robert Roath
Robert Roath
1,072 Points

Here 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?

2 Answers

Steven Parker
Steven Parker
229,785 Points

You 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.

This is how your code should look.

const isAdmin = false; const isStudent = true; let message;

if ( isAdmin ) { message = 'Welcome admin'; }