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

if ( a > b ) { alert ('a is greater than b') } else if ( a !> b ) { alert ('a is NOT greather than b') }

What's wrong here

script.js
var a = 10;
var b = 20;
var c = 30;

if ( a > b ) {
  alert ('a is greater than b') 
} 


else if ( a !> b ) {
  alert ('a is NOT greather 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

Drew Butcher
Drew Butcher
33,160 Points

my guess would be that you would want to say:

var a = 10;
var b = 20;
var c = 30;

if ( a > b ) {
  alert ('a is greater than b') 
} 


else if ( !(a>b) ) {
  alert ('a is NOT greather than b') 
}

Does that work for you?

However, logically wise you could just use the ''else'' instead of else if; because, if a>b false then a is not great then b. Never the less if you want to use ''else if'' have have the condition checked I believe that should work for you.

Yes that works, thank you. Somehow it did not accept else if as a proper answer.

"!>" is not a valid comparator, if you want the opposite of greater than you can just use less than. Obviously if you want to negate the expression for some reason you can use what Drew Butcher suggested above.