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 JavaScript Basics (Retired) Making Decisions with Conditional Statements Add a Final Else Clause

alert 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?"

script.js
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?");
}
index.html
<!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
MOD
Jason Anders
Treehouse Moderator 145,860 Points

Hey 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! :)

So, I don't need to add

else (isAdmin && isStudent=false);

Thank You!

Jason Anders
Jason Anders
Treehouse Moderator 145,860 Points

Nope. Just the else. The if and the else if has already done that job. The if returned false and the else if returned false, so the else 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)... ;

You 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?");
}

Thank You!

Michael Cerchia
PLUS
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?");
}

Thank you. This is more clear

This really helped me! Thanks guys :)