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

I am trying to do boolean conditional statement and it does not seem to be working

Here is the code. It keeps telling me there is an error. var isAdmin = false; var isStudent = false;

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

thanks so much

this is what the error says Did you add a final else clause at the end of the conditional statement?

2 Answers

Hi Monica,

Your last conditional statement is a bit redundant. Try:

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

ok thanks! what is the difference between the else and the else if clause?

Not much. Just else would mean, Do the following things if the previous conditional is falsey. An else if says, Do the following things if the previous conditional is falsey and if this conditional is true.

The way you had it would work... it's just a bit redundant. Let me know if that's not clear :)

thanks!