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 Using Comparison Operators

The video does not tell me how to state if on variable is not greater than another variable.

I have looked over the video multiple times, and i still couldn't find any info on how to solve the code.

script.js
var a = 10;
var b = 20;
var c = 30;
if (a > b){
 alert('a is greater than b');
} else (a < b){
  alert('a is not greater than b');
}
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

You have correctly checked to see if a is greater than b, the problem is in the if else statement itself. The else part of the statement is run if the if fails and does not need any conditionals by it (an else if would be used for that). All you need to do is remove the brackets by the else and your code will pass

if (a > b){
 alert('a is greater than b');
} else {
  alert('a is not greater than b');
}
Clayton Perszyk
MOD
Clayton Perszyk
Treehouse Moderator 48,850 Points

if a is not greater than b, then you b is greater than a. So, your else clause wont need to compare the values, as you already know there can only be two outcomes and if the first one fails, the second one has to be the answer.

Sorry if that sounded like a riddle.