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.

JavaScript JavaScript Basics Making Decisions in Your Code with Conditional Statements Add a Final 'else' Clause

Add a final else clause to this conditional statement. If both the isAdmin and isStudent variables are false, the value

Add a final else clause to this conditional statement. If both the isAdmin and isStudent variables are false, the value

script.js
const isAdmin = false;
const isStudent = false;
let message;

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

} else { isAdmin + isStudent = false 
message= ("Access denied");
}

2 Answers

Add a final else clause to this conditional statement. If both the isAdmin and isStudent variables are false, the value of the message variable should be "Access denied".

if ( isAdmin ) { message = 'Welcome admin'; } else if ( isStudent ) { message = 'Welcome student'; } else (false) = message = 'Access denied' }

I have used 2 or three different answers and I get two different bummer answers.

Cameron Childres
MOD
Cameron Childres
Treehouse Moderator 11,719 Points

Hi Robert,

if and else if statements take conditionals, else does not. Remove your final conditional and you should be good to go:

else {
message = ("Access denied");
}

Remember that else will only run if the other statements don't evaluate to true. Your code checks if isAdmin is true, then if isStudent is true, so the final else will only be able to run if both of those conditions are false.

Hope this helps! Let me know if you have any questions.