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

Louise Turner
Louise Turner
710 Points

Condition if else statement trouble

I can't seem to get this correct and not sure why this isn't passing

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'); }

2 Answers

Shawn Flanigan
PLUS
Shawn Flanigan
Courses Plus Student 15,815 Points

Hi Louise: I haven't looked at the challenge, but just glancing at your code...you seem to be missing an opening curly brace after "else". You've also got an extra "a" thrown in before your second alert statement.

Shawn Flanigan
Shawn Flanigan
Courses Plus Student 15,815 Points

Louise: I'm having a hard time tracking down the challenge you're completing, but syntax errors aside, the logic of your code looks good. In the end, the following code works...but without seeing the challenge, it's hard to say if it will meet all of the objectives.

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');
}

If this still isn't passing, please let us know which course you're taking and the title of the challenge and I'll look into it.

Hope that helps!

Louise Turner
Louise Turner
710 Points

Hi Shaun,

Thanks for your help. I'm completing 'Javascript Basics' and the challenge 'Review Conditional Statements and Comparison Operators '

I've just tried the code again with your suggestions and it's worked!

Thanks :)