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

not sure im doing this correctly

i took 2 weeks off javascript and am refreshing

script.js
var isAdmin = true;
var isStudent = false;
if (isAdmin= true) {prompt("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>

error i got was the following: Did you add true inside the parentheses of the conditional statement?

1 Answer

Umesh Ravji
Umesh Ravji
42,386 Points

Hi Gena, there are two small issues with the code.

if (isAdmin = true) { // [1]
    prompt("Welcome Administrator") // [2]
};

Two weeks is a while, here's what you may have forgotten.

  1. Comparisons to see if two 'things' are equal are done using double equals (==). Assignment is done using a single equals (=), so you aren't actually comparing the value of isAdmin to true, you are assigning it the value of true.

  2. Prompts are used to gather inputs from the user. You want to use an alert here to display the message because you are simply telling them something.

You don't need the semicolon at the end of an if statement.

if (isAdmin == true) {
    alert("Welcome Administrator");
}