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 Challenge 1 Task 1

I don't understand what to put in the 'else' statement.

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

if ( isAdmin ) {
    alert('Welcome administrator')
} else if (isStudent) {
    alert('Welcome student')
    if (false)
} else {

  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

Hey Brenda,

You are so very close with your code! You want to take out the "if (false)" right above the else statement in your code. The challenge is just letting you know that the else statement activates after both isStudent and isAdmin are false.

Nicholas Nelson
Nicholas Nelson
24,526 Points

Hmm if the quiz is not accepting your answer, I'd say it has to do with the "if(false)" that has been added. If/else statements typically look something like...

if (condition1) {
    // code... 
} else if (condition2){
   // code...
} else {
    // code...
}

If condition1 is met then the code inside that block and does not run further. If condition1 is not met, and say condition 2 is also not met, then the code in the 'else' block will run. So your 'else' block is your default or backup plan.

In this specific challenge we what the alert('Who are you?'); to be our backup plan. :) Just another pointer is that it is good practice/habit to end all your statements with semi-colons. :)