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 Making Decisions in Your Code with Conditional Statements Add a Final 'else' Clause

Can you please guide me in right direction?

Add a final else clause to this conditional statement. If both the isAdmin and isStudent variables are false, the value

script.js
const isAdmin = false;
const isStudent = false;
let message;

if ( isAdmin ) {
  message = 'Welcome admin';
} else if ( isStudent ) {
  message = 'Welcome student';
} 

I tried it this way too, and I keep getting the same message

} else { message = ("Access denied."); }

Steven Parker
Steven Parker
231,269 Points

Challenges are very picky about outputs. It's not expecting to see the punctuation.

6 Answers

This is what I have and I keep getting cannot read property "1" null? Please help { } else { console.log = ("Access denied."); }

Steven Parker
Steven Parker
231,269 Points

You don't need to log anything, just update the "message" variable like the other conditions do.

Steve:

Add a final else clause to this conditional statement. If both the isAdmin and isStudent variables are false, the value of the message variable should be "Access denied".

You ask me to remove punctuation. It till give me the same error.

} else { message = ('Access denied'); }

Steven Parker
Steven Parker
231,269 Points

It's not obvious from that snippet. Please show the entire code (use Markdown formatting to preserve the code's appearance).

Steve: This the entire code:

Question: Create a conditional statement that tests if the isAdmin variable is true. If it's true, set the value of the message variable to "Welcome admin".

const isAdmin = true; const isStudent = false; let message; cont guess = prompt('isAdmin true'); let correctGuess = True if (true) { console.log ("Welcome admin".) }

Steven Parker
Steven Parker
231,269 Points

Is this the same challenge? This code is very different from what you originally asked about! It kind of looks like you mixed the code for this challenge with some from a different challenge.

This challenge doesn't use "prompt", and it doesn't "log" anything, and there's no guessing involved!

And please, when you post code, always use Markdown formatting to preserve the code's appearance.

Is there anyway I can speak with you or is there another way I can get help. I have watch the Markdown formatting video twice. That'a not helping me show you what I am looking for. I only have 2 problems that I am working on to be done with the program. Please help or give me information to get in contact with some who can better help. Thanks

I'm trying to send it the way you want. this not is launch but an objective?

Code

To install the latest version of NPM, you can type `npm install npm@latest -g

const isAdmin = false;
const isStudent = false;
let message;

if ( isAdmin ) {
  message = 'Welcome admin';
} else if ( isStudent ) {
  message = 'Welcome student';
} else  isAdmin + isStudent = false 
message= 'Access denied';
}

Question to code: Add a final else clause to this conditional statement. If both the isAdmin and isStudent variables are false, the value of the message variable should be "Access denied".

I hope this is better steve

Steven Parker
Steven Parker
231,269 Points

Close! But a final "else" does not need any kind of test. But it does need an open brace to start the code block and match the closing one at the end.

Steven Parker
Steven Parker
231,269 Points

The code you will add will look much like the "else if" section already provided, but a final "else" doesn't have a conditional expression.

Give it a shot and write again (showing the code you added) if you still have trouble.