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

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

Douglas Counts
Douglas Counts
10,126 Points

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