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

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,361 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");
}