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 trialNicollette Whitfield
4,526 PointsAdd 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
Treehouse TeacherAs 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.
Gertrude Dawson
5,371 PointsI 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
10,419 PointsYou 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
33,501 PointsThis is what I used to pass:
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");
}
Lazarus Mbofana
10,941 Pointsvar 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'); }
Rabit Ebibi
5,875 Pointsif(a > b) { alert('a is greater than b'); } else { alert('a is NOT greater than b'); } RIGHT ANSWER
Trinity Shelly
2,928 Pointsvar 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
Sara Swenson
3,510 Pointsconst 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'); }
Kajuanna Smith
Full Stack JavaScript Techdegree Graduate 13,609 Pointsuse console.log instead of alert
Nicollette Whitfield
4,526 PointsNicollette Whitfield
4,526 PointsMy 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!
Isaiah Carter
11,116 PointsIsaiah Carter
11,116 PointsI receive the following error message: Did you use
console.log()
inside theif
andelse
blocks?Ben Harmata
8,800 PointsBen Harmata
8,800 PointsI used 'console.log' in place of 'alert' and it worked for me!