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

please I don't want the actual answer, just an outline of how to tackle this!

I'm not sure how to start, should I first create a prompt string, then a conditional statement

script.js
var isAdmin = true;
var isStudent = false;

if (true) { 
  alert(welcome administrator)
    }
 else {
    }
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>
eslam said
eslam said
Courses Plus Student 6,734 Points

Your code is fine the mistake you made is the message inside alert, when you write a string you need to put it insde a single or double code like that :

   alert("Welcome administrator")

Just in case you're struggling with conditional statements : lets say we have a variable with a name

   var name = "niels";
   if ( name === "niels" ) {
      alert("Yes it is");
   } else {
      alert("It's not")
   }

i am checking if name === ( equal to ) the value of the string

// do something

else

// do something else

lets take another example:

lets say i want to capture users age and if age is less than 18 then alert that he cannot browser the website if hes above 18 alert welcome feel free to use our website

1- Creating a variable to hold the user input on it

var age = prompt('How old are you ?');

2- creating if & else statements to check if user age it less than or greater than 18

   if ( age < 18 ) {
   alert('Sorry you cannot use our website');
} else {
   alert('Welcome and happy browsing !');
}

if anything still unclear ask for it

1 Answer

Steven Parker
Steven Parker
231,236 Points

Your conditional structure is good, except you won't need an "else" clause for this particular challenge. But instead of "true" you need to substitute the name of the boolean value you want to test. You'll only need a name because boolean values don't need to be compared to anything.

Then in your "alert" call, be sure to put quotes around the sting you want to display.

I'll bet you'll get it now.