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

monique champagne
monique champagne
761 Points

not sure why my answer is wrong-

cant figure out what im doing wrong here..

script.js
const isAdmin = true;
const isStudent = false;
let message = "Welcome admin";
if ( isAdmin ) {
  console.log(message);
}

3 Answers

Heidi Fryzell
seal-mask
MOD
.a{fill-rule:evenodd;}techdegree seal-36
Heidi Fryzell
Front End Web Development Treehouse Moderator 25,178 Points

Hi Monique,

The instructions say if the isAdmin variable is true, set the value of the message variable to "Welcome admin".

So inside the if statement is where you are going to set the value of the variable.

In your code you set the value of the variable message outside the if statement and you console logged the message inside the if statement.

You don't need to console log the message in this challenge.

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

if (isAdmin){
  //assign variable here, you already declared it above with "let"
}

I hope this helps and happy coding!

monique champagne
monique champagne
761 Points

oh ok- i think i get it... would this be better?

const isAdmin = true;
const isStudent = false;
let message;
if ( isAdmin ) {
 message = "Welcome Admin!";
}

is the let message ok to just leave like it is? i would have thought it would be something like let message = " "; so it had some kind of blank to fill in... thanks so much for your help!

Heidi Fryzell
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Heidi Fryzell
Front End Web Development Treehouse Moderator 25,178 Points

Yes, that would work, except one little thing. You have to match exactly what they ask for in the instructions.

So for the welcome admin message you can't add punctuation or capitalization. It has to be exactly how they did in the instructions

message = "Welcome admin";