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

Why didn't my code run?

I have to do an objective, and the objective starts off with var a = 10 var b = 20 var c = 30 Here is my code that I typed.

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

2 Answers

Ken Howard
STAFF
Ken Howard
Treehouse Guest Teacher

The code needs to be written using the greater than operator >. Also, when referencing a variable you don't include the var keyword. var should only be used when assigning a value to a new variable name.

var a = 10,
      b = 20,
      c = 30;
if (a > b) {
  alert('a is greater than var b');
} else {
  alert('a is not greater than b');
}

Thank you Ken.