Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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,624 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,624 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 :)