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

question saying did you use a alert method

Hilary Katsande question saying did you use a alert method

script.js
var a = 10;
var b = 20;
var c = 30;
if ('a>b') {
}else {
alert("a 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>

3 Answers

Omprakash Panigrahi
Omprakash Panigrahi
9,632 Points

Hello! In the if clause you have a string ('a > b'), instead if comparing two variables if(a > b). Inside an if clause, if there is only string like if("something") , it will always amount to a truthy value and the else clause wont be executed. For example,

    if("something"){
      alert("This will always amount to true");
    }
    else {
      alert("This wont be executed");
    }

It looks like that is the issue, a>b should not be in quotes because you defined their day type as integers.

Sam Gord
Sam Gord
14,084 Points

i don't clearly get what the problem is here , but i think the condition in the if statement shouldn't be represented as a string like what you have , you might wanna change it this way :

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