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

how do I include TWO false variables in an ELSE statement?

var isAdmin = false; var isStudent = false;

if ( isAdmin ) { alert('Welcome administrator'); } else if (isStudent) { alert('Welcome student'); } else ( isAdmin isStudent) {alert("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) {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>

2 Answers

Hi Michael,
An else statement will not have a following set of parentheses with a condition in them. Instead, it just has a code block following it. Also, since you have already checked to see if isAdmin and isStudent are true in the previous if and else if statements you do not need to recheck that they are false. Therefore, if you remove the ( isAdmin isStudent ) from your code it will be properly formatted:

else {alert("Who are you?");}

However, if you do want to test for two conditions in one statement you can use the logical and (&&) or logical or (||). In this case you would need to change the else to another else if since else cannot make use of an additional condition (it is kind of like a finally block). Here is how it would be coded for these two conditions:

else if ( !isAdmin && !isStudent ) {alert("Who are you?");}

This states that you would like to print an alert if isAdmin is false AND if isStudent is false.

thanks!!

With "else" you don't use () just {}.

else { alert("Who are you?"); }

Ah! duh. thanks.