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

JavaScript Basics - Boolean Value Challange

Hi I can't seem to pass this challenge, can someone tell me where I am going wrong please?

Thanks.

script.js
var isAdmin = false;
var isStudent = false;

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

2 Answers

Hi, you don't need the (false) expression in the else statement. That test wouldn't make much sense, as it is testing if 'false' is 'true'. You don't need any expression there at all to catch when both isAdmin and isStudent are false.

var isAdmin = false;
var isStudent = false;

if ( isAdmin === true ) {
    alert('Welcome administrator')
} else if (isStudent === true) {
    alert('Welcome student')
} else {
  alert('Who are you?');
}
Jason Anders
MOD
Jason Anders
Treehouse Moderator 145,860 Points

Hi Daniella,

You are close, but for the final 'else' statement, you don't need to pass in a value (you passed in 'false'). If the 'if' conditional fails, it moves on to the 'else if.' If that one fails, it will run the 'else' block regardless.

So, all you need is

else {
  alert('Who are you?')
}

Hope that helps. Keep Coding! :)