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

Teacher Russell
Teacher Russell
16,873 Points

a basic if statement

What are they asking for here?

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

2 Answers

Thomas Fildes
Thomas Fildes
22,687 Points

Hi Russell,

You are nearly there. You need to create an alert dialog rather than a variable storing an answer prompt inside the code block of the if statement. Also, in conditional statements you need to use the double equals (==) logical operator because the single equals is used for assigning values like you do with variables and the double equals checks to see if something is equal to something.

Please see the below code I used to pass this challenge for further assistance:

var isAdmin = true;
var isStudent = false;

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

Hope this helps! Happy Coding!!!

Teacher Russell
Teacher Russell
16,873 Points

THanks mate, it's always too many hours of practice without a break. The dumbest mistakes!:)

The HTML is not quite relevant to post (in this case). So what this If statement does is basicly compare the variable "isAdmin" with the value "true". So if the variable "isAdmin" equals true, you'll get a prompt saying "Welcome administrator". Whatever you'll type in the input field will be stored in the variable "answer".