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

peterson st gourdain
peterson st gourdain
931 Points

I can't see my mistake

shine some clarification on this for me

script.js
var isAdmin = true;
var isStudent = false;
if (isAdmin is true) {

} else if (alert("Welcome administrator")); {

}
index.html
<!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

Steven Parker
Steven Parker
231,236 Points

Here's a few hints:

  • the word "is" is not a JavaScript operator
  • the parentheses following an "if" should contain a comparison expression
  • conditional code goes between the braces that come after the conditional expression
  • there should not be a semicolon between an "if" condition and the brace of the code block
Paolo Scamardella
Paolo Scamardella
24,828 Points

I'm not sure what you are trying to accomplish here, but your comparison is wrong. You need to use === (triple equals) to compare values. Second, JavaScript's alert method does not return a boolean but returns no value, so it does not make sense to call the method inside else if parentheses.

By judging your code, maybe you want to do this?

var isAdmin = true;
var isStudent = false;

if (isAdmin === true) { // or just if(isAdmin)
   alert("Welcome administrator")
} else {
   // code for not an admin
}
Steven Parker
Steven Parker
231,236 Points

:information_source: The strict equality comparison ("===") will work here but isn't necessary because there's no risk of a type mismatch. A normal comparison ("==") is adequate.