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
Monica Anderson
3,621 PointsI 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
2 Answers
miikis
44,957 PointsHi 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?');
}
Monica Anderson
3,621 Pointsok thanks! what is the difference between the else and the else if clause?
miikis
44,957 PointsNot 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 :)
Monica Anderson
3,621 Pointsthanks!
Monica Anderson
3,621 PointsMonica Anderson
3,621 Pointsthis is what the error says Did you add a final
elseclause at the end of the conditional statement?