Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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,714 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.

1 Answer

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