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

Add a conditional statement that tests if the value in the variable a is greater than the value in variable b. If it is,

Add a conditional statement that tests if the value in the variable a is greater than the value in variable b. If it is, pop up an alert with the message 'a is greater than b'; also add an else clause that pops up the message 'a is not greater than b.'

var a = 10;

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

9 Answers

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

As far as I can see you're just missing some semicolons after your alert statements. See the code below:

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

Also, it seems that you removed the b and c variable. So it's going to have no idea if b is less than a or not, because b no longer exists.

My code didnt completely copy over. Now that you say that about the initial brackets it is SOOO obvious. You wouldn't believe how long I looked at that. Thank you!

I receive the following error message: Did you use console.log() inside the if and else blocks?

I used 'console.log' in place of 'alert' and it worked for me!

Gertrude Dawson
Gertrude Dawson
5,371 Points

I would of had a easy time with all these problems if I could see my work in the previous Workspaces while I solved the problem. When I do web searches and go to the other sites they always so me slightly different ways of coding similar problems and it is never the correct way for the problem in question. I forgot about the "<p> <?/p>"

Rouillie Wilkerson
Rouillie Wilkerson
10,419 Points

You know, after struggling with this, I just removed the "var c = 30;" and it worked! Takeaway? If it doesn't belong there, remove it! Hope I'm right. :)

Tom Nguyen
Tom Nguyen
33,500 Points

This is what I used to pass:

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

if ( a > b){
  console.log("a is greater than b");
}else{
  console.log("a is not greater than b");
}

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

if(a > b) { console.log('a is greater than b'); } else { console.log('a is not greater than b'); }

if(a > b) { alert('a is greater than b'); } else { alert('a is NOT greater than b'); } RIGHT ANSWER

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

if(a > b) { console.log('a is greater than b'); } else { console.log('a is not greater than b'); }

correct answer

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

if(a > b) { console.log('a is greater than b'); } else { console.log('a is not greater than b'); }

use console.log instead of alert