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 trialsarah shelden
8,332 Pointssyntax 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") ;
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JavaScript Basics</title>
</head>
<body>
<script src="script.js"></script>
</body>
</html>
2 Answers
Trent Stenoien
Full Stack JavaScript Techdegree Graduate 21,632 Pointsvar 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
16,529 PointsYour code doesn't check isAdmin variable and you forget } at the end again.