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 trialYerVonda Colbert
5,846 PointsCreate a conditional statement that tests if the isAdmin variable is true. If it's true, set the value of the message va
const isAdmin = true;
const isStudent = false;
let message;
let isAdmin = true;
let greeting;
if (isAdmin) {
greeting = "Welcome admin".
}
2 Answers
Steven Parker
231,269 PointsThe 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
YerVonda Colbert
5,846 PointsI'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".) }
YerVonda Colbert
5,846 Pointsi got it.. thanks
Steven Parker
231,269 PointsSteven Parker
231,269 PointsYerVonda Colbert — Glad to help. You can mark a question solved by choosing a "best answer".
And happy coding!
Zachary Smith
Full Stack JavaScript Techdegree Graduate 16,616 PointsZachary Smith
Full Stack JavaScript Techdegree Graduate 16,616 PointsSo 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
231,269 PointsSteven Parker
231,269 PointsIt'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.
Zachary Smith
Full Stack JavaScript Techdegree Graduate 16,616 PointsZachary Smith
Full Stack JavaScript Techdegree Graduate 16,616 PointsThank you, Steven!