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
Dominik Sikiric
2,059 PointsWhy 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?");
}
2 Answers
Geoff Parsons
11,679 PointsElse 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.
Dominik Sikiric
2,059 PointsOh 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?");
}
Geoff Parsons
11,679 PointsIf 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?");
}
Dominik Sikiric
2,059 Pointsthanks :)
Johnson Report
563 PointsJohnson Report
563 PointsHow does the argument of
falsework for the lastelse?