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

Why this isn't working in Javascript

Add a filan else clause to this conditional statement so that if the isAdmin variable and isStudent variables are both false an alert opens with message "Who are you"

var isAdmin = false;
var isStudent = false;

if ( isAdmin === true ) {
    alert('Welcome administrator');
} else if (isStudent === true) {
    alert('Welcome student');

} else ( false ) {
  alert("Who are you?");
}

How does the argument of false work for the last else?

var isAdmin = false; 
var isStudent = false;

if ( isAdmin === true ) { 
alert('Welcome administrator'); 
} 
else if (isStudent === true) { 
alert('Welcome student');

} 
else (false) { // what is this part doing? 
alert("Who are you?");
 } 

2 Answers

Else statements don't take a condition - they're just what happens if all other statements fail - so you can remove the "( false )" from after your else.

Oh I see. I figured it out, I put just "empty" else at the end and removed both === true above . But, would it be correct if I didn't remove === true above? so like this;

var isAdmin = false; 
var isStudent = false;

if ( isAdmin === true ) { 
alert('Welcome administrator'); 
} 
else if (isStudent === true) { 
alert('Welcome student');

} 
else { 
alert("Who are you?");
 }

If you're using booleans as you are here you don't need to compare them to anything, you can actually just check if ( isAdmin )

var isAdmin = false; 
var isStudent = false;

if ( isAdmin ) { 
   alert('Welcome administrator'); 
} else if (isStudent) { 
   alert('Welcome student');
} else { 
   alert("Who are you?");
 }

thanks :)