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

That is my final Question about Javascript . I am stuck in here . what should I write ? what is my mistake. ? please

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

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

1 Answer

The following line:

( isAdmin + isStudent === false );

is breaking up your if-then-else statement flow as it is after your closing } for the if statement above that line and you probably intended for that line to also be run with the line above it. Your if-then-else logic should look like so:

if ( isAdmin ) {
    // do something if isAdmin
} else if ( isStudent ) {
   // do something if NOT isAdmin but isStudent
} else {
   // do something if NOT isAdmin and is NOT isStudent
}

I think you are wanting to do this:

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

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

I hope this helps....

-Doug