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 trialGAYATHRI ELURI
2,768 Pointsalert message opens a dialog box "who are you?"
Add a final else clause to this conditional statement so that if the isAdmin variable and isStudent variables are both false an alert opens with the message "Who are you?"
var isAdmin = false;
var isStudent = false;
if ( isAdmin )
{
alert('Welcome administrator');
} else if (isStudent)
{
alert('Welcome student');
}
else (isAdmin && isStudent=false);
{
alert("Who are you?");
}
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JavaScript Basics</title>
</head>
<body>
<script src="script.js"></script>
</body>
</html>
4 Answers
Jason Anders
Treehouse Moderator 145,860 PointsHey there,
You are are the right track, but you've just added too much. The if
checks for Student... The else if
checks for admin, so you just need and else clause (that doesn't compare anything), it will just execute only if the previous two are both false.
else {
alert("Who are you?")
}
Hope this helps. Keep coding! :)
Chyno Deluxe
16,936 PointsYou are close. but a single else clause cannot have conditions. The else is a final "catch all" clause. Only if's and else if's are allow to have conditional statments.
var isAdmin = false;
var isStudent = false;
if ( isAdmin )
{
alert('Welcome administrator');
} else if (isStudent)
{
alert('Welcome student');
} else {
alert("Who are you?");
}
GAYATHRI ELURI
2,768 PointsThank You!
Michael Cerchia
Courses Plus Student 8,572 Points'=' is an assignment operator. You need to test to see if isAdmin is false and isAdmin is false. You do that like this:
else (isAdmin === false && isStudent === false);
{
alert("Who are you?");
}
Michael Cerchia
Courses Plus Student 8,572 Pointsedit: else if, not else
GAYATHRI ELURI
2,768 PointsThank you. This is more clear
Ada N
Courses Plus Student 4,246 PointsThis really helped me! Thanks guys :)
GAYATHRI ELURI
2,768 PointsGAYATHRI ELURI
2,768 PointsSo, I don't need to add
else (isAdmin && isStudent=false);
GAYATHRI ELURI
2,768 PointsGAYATHRI ELURI
2,768 PointsThank You!
Jason Anders
Treehouse Moderator 145,860 PointsJason Anders
Treehouse Moderator 145,860 PointsNope. Just the
else
. Theif
and theelse if
has already done that job. Theif
returned false and theelse if
returned false, so theelse
executes because both are false.Just a note: if you were to do multiple comparisons, the syntax you have is incorrect. As you have it, it will return an error. You would need to do `else if {(isAdmin == false) && (isStudent == false)... ;