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

Trouble with final else clause?

In this code challenge, I am instructed to create a final else clause that the computer will alert "Who are you?" in the case that both isAdmin and isStudent are false.

Everything I've tried has come back as a "parse error."

In the below example:

var isAdmin = false
var isStudent = false

if ( isAdmin) {
     alert('Welcome Administrator');
} else if ( isStudent ) {
     alert('Welcome Student');
}

Wouldn't the two variables already be false? And if so, wouldn't I change the values to true so that if they are false I can tell the computer to alert the user, "Who are you?"

I've tried a few different variations of solving this challenge and I never get any other prompts other than 'parse error'.

A little help please?

3 Answers

Stone Preston
Stone Preston
42,016 Points

the task states: 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?"

you just need to add an else block on to the end:

var isAdmin = false;
var isStudent = false;

if ( isAdmin ) {

    // runs if isAdmin == True
    alert('Welcome administrator')

} else if (isStudent) {

    // runs if isStudent == True the condition above it is false
    alert('Welcome student')

} else {

  // this runs if and only if the above conditions are false
  alert("Who are you?")

}

in the above code, isAdmin is false so the code in the if block does not run. then it checks isStudent, which is also false so the code in that block does not run, then it goes down to the else, which will only run if the other two conditions are false (which they are)

Wow... hahaha.... So i was just extremely over-thinking it.

Thanks for the quick reply!

Edgar Lazo
Edgar Lazo
3,057 Points

I had some difficulties with this task to0, make sure you type everything as it shows.

alert('Who are you ?');

Thank you! It helps a lot