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 Write an 'if' Statement

terry okey
terry okey
3,187 Points

Stuck on If statement.

I can't figure out why I'm stuck on this stupid little thing, I've tried ten different versions of code?

script.js
const isAdmin = true;
const isStudent = false;
if ( isAdmin === 'true') {
message = 'Welcome admin';
}

3 Answers

Amber Stevens
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Amber Stevens
Treehouse Project Reviewer

Hi terry okey ! So the problem here is that you're testing to see if isAdmin is evaluating to the STRING 'true'. You want it to test for boolean value true, NOT the string "true". Try removing the quotation marks around the word true in your if statement and it should work ok.

terry okey
terry okey
3,187 Points

Oh wow, I completely forgot. A boolean would never have quotes. Wow good lesson to learn.

I am also stuck on this challenge...not sure why this is incorrect?

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

if ( isAdmin ) { message = 'Welcome admin.'; }

terry okey
terry okey
3,187 Points

In my case I had erroneously added the single quotes to the statement. Anytime you add single quotes in javascript it means that it is a string. I was supposed to be testing for a boolean value, which is written without quotes and can only be evaluated as yes or no. But in this case, I was not getting yes or no because on the third line I put quotes around the word "true". Anything in quotes can never be evaluated as a boolean, only as a string.

In your case I'm not sure, but it looks to me like you have two statements on one line with a semicolon in between. I believe javascript always ends a line when it hits the semicolon. I think javascript is seeing the semicolon after your word true, and skipping to the next line. I think if you put the Const isStudent etc on the next line down your code will work?