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

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

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

let isAdmin = true;
let greeting;
if (isAdmin) {
 greeting = "Welcome admin".
}

2 Answers

Steven Parker
Steven Parker
231,248 Points

The instructions ask you to "set the value of the message variable", but this code is setting "greeting" instead.

Also:

  • you don't need to create any new variables
  • "isAdmin" is already created and set by the supplied code
  • javascript statements should end with a semicolon instead of a period
Steven Parker
Steven Parker
231,248 Points

YerVonda Colbert — Glad to help. You can mark a question solved by choosing a "best answer".
And happy coding!

So if I am understanding correctly, you can have a function and not assign a value to it when you first put it in the program, but you need to assign it a value eventually? For example...

let message;

Why would you not assign a value to it at first like the isAdmin or isStudent functions? Sorry if that isn't clear - extremely new to this.

Steven Parker
Steven Parker
231,248 Points

It's considered good practice to define global variables at the beginning, even if you don't know what value they will get yet. It might also be needed to make the variable available later (for setting and reading) to functions. As you progress, you'll learn about the concept of "scope" which determines when and where variables can be accessed in the program.

Thank you, Steven!

I'm having problems with this one can anyone help please.

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

i got it.. thanks