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

david Ramirez
PLUS
david Ramirez
Courses Plus Student 2,798 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
231,269 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
231,269 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")
}