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 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
Cameron Childres
11,820 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.