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 (Retired) Making Decisions with Conditional Statements A Basic If Statement

syntax error

Add a conditional statement that tests to see if the isAdmin variable is true. If it is then open an alert with the message "Welcome administrator".

I am not sure what i am missing?

var isAdmin = true;
var isStudent = false;

if (true)
{ prompt ("Welcome administrator") ;
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  <title>JavaScript Basics</title>
<script src="script.js"></script>

2 Answers

Trent Stenoien
.a{fill-rule:evenodd;}techdegree seal-36
Trent Stenoien
Full Stack JavaScript Techdegree Graduate 20,034 Points
var isAdmin = true;
var isStudent = false;

// Changed true to 'isAdmin' and added an ending curly brace '}'
if (isAdmin) { prompt ("Welcome administrator") };

If statements will execute if the expression within the parenthesis returns 'true'. Therefore "if (true) { ... }" will always execute in the same way that "if (false) ....." never will. Replace with "if (isAdmin === true) ..." or simply "if (isAdmin) ..."

Finally, you are getting a syntax error because you forgot to close the curly braces { }. It's an easy thing to forget, but will stop your code in its tracks. Personally, I try to close them as soon as I open them, then go back to enter my code in between.

Andrey Misikhin
Andrey Misikhin
16,529 Points

Your code doesn't check isAdmin variable and you forget } at the end again.