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

Joseph Harlow
seal-mask
.a{fill-rule:evenodd;}techdegree
Joseph Harlow
Front End Web Development Techdegree Student 8,243 Points

Create a conditional statement that tests if the isAdmin variable is true. If it's true, set the value of the message va

Please help. Stuck with this once.

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

let isAdmin === true;
let message;
if (isAdmin) {
 message = "Welcome admin".
}
Tim Oltman
Tim Oltman
7,730 Points

Hi Joseph,

You basically have it. The isAdmin is already defined for you on the first line so you don't have to define it again using 'let'. Same with 'message'. The only thing you have to write is the if-statement.

3 Answers

1- In your code, you're declaring the variable isAdmin twice, and you can't do that... And you can change the value only if used let instead of const, example:

let isAdmin = true;

isAdmin = false;

2- same for message variable, you can't name two variables the same! So the correct code should be:

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

if (isAdmin) {
 message = "Welcome admin";
}

3- Note: replace the dot with a semicolon in the if statement code block

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

please help me out guys

Thanks Joo, I got similarly caught up, but I was thinking I needed to have it written as:

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

if ( isAdmin ) { let message = "Welcome admin"; }

You helped me catch that I didnt need to "let" the message the second time. I only needed to redefine message.