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

seong lee
seong lee
4,503 Points

I need help with this conditional statement

I need help solving this and I want to know why isadmin and is student = false on the first two lines

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>

3 Answers

Ari Misha
Ari Misha
19,323 Points

Hiya there! First off, else keyword doesnt take any argument, its like saying "Do this if this is true, do that if that is true, and if nothing works , do these". The else conditional is like safety measure that you implement when you know a certain conditions will fail but you still wanna achieve some result, right? Now regarding your code, just remove the (isAdmin, isStudent = false) -- it'll throw a syntax error, thats why you need to remove it. Also, default values of isStudent and isAdmin is false so you dont have to worry about 'em.

Here is the code in case you still get stucked:

var isAdmin = false;
var isStudent = false;

if ( isAdmin ) {
    alert('Welcome administrator');
} else if (isStudent) {
    alert('Welcome student');
} else {
  alert('Who are you?')
}

~ Ari

seong lee
seong lee
4,503 Points

thank you so much I made the worst mistake ever :)

seong lee
seong lee
4,503 Points

but now I know