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

scott Walker
scott Walker
2,506 Points

ive took a few days away and i seem to have forgotten whats wrong here

i initally thought maybe i needed

if var a = b

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

if 'a' < 'b' 
{ 
  alert('a is greater than b');
  else { 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

Few things that should help: 1) When you're comparing variables, you don't need quote marks - the quote marks make them strings instead. So while you've got this:

if 'a' < 'b' 

You want this:

if a < b

2) The challenge is looking to see if a is greater than b. Right now your code is looking to see if b is greater than a. It helps me to remember that the open end is the "greater" end when you are working with those comparisons.

3) You are missing a closing curly bracket for the opening if statement. You've got:

if 'a' < 'b' 
{ 
  alert('a is greater than b');
  else { alert('a is not greater than b');
       }

and you just need to add a closing } right before the else so it looks like this:

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

if 'a' < 'b' { 
alert('a is greater than b');
 } else { 
alert('a is not greater than b');
       }

Hope that helps!

Whoops! Sorry, I should have fixed the other issues I mentioned before pasting the final answer - everything I mentioned before the last post still stands.

Piotr Manczak
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Piotr Manczak
Front End Web Development Techdegree Graduate 29,363 Points

After if you should place a and b in (). if ( a < b ) { alert('a is greater than b'); } else { alert('a is not greater than b'); } Try that, it should work.