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

david Ramirez
PLUS
david Ramirez
Courses Plus Student 2,797 Points

help please

i don't understand is it a if statement then a else if statement ?

script.js
var isAdmin = true;
var isStudent = false;
if(true){
  document.write('true')
}
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
218,694 Points

Here's some hints:

  • testing the value true is not a conditional statement (it's a certainty!)
  • when testing a condition, you must name the value being tested in the if statement
  • for this challenge, you won't need an "else"
  • the challenge wants you to use alert, not document.write
  • it also wants you to use a specific message. You can cut-and-paste that message to avoid typo's
Steven Parker
Steven Parker
218,694 Points

Yes, it will be just an if (and an alert).

I was betting you'd get it without an explicit spoiler, but I see someone's given one already anyway.

The challenge asks that you create a conditional statement that test to see if the isAdmin variable is true. Then, If it is then open an alert with the message "Welcome administrator".

var isAdmin = true;
var isStudent = false;

if(isAdmin){
  alert("Welcome administrator")
}