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

Kevin Jervis
Kevin Jervis
2,600 Points

Conditional Statements

I suspect that I have made a mistake on line 2. If someone can point me in the right direction that would be awesome.

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

6 Answers

Charles Wanjohi
Charles Wanjohi
9,235 Points

Remove the var inside the if statement.It should be:

if(a>10){

}

you arent supposed to redeclare variable a in the if condition

and let me correct my self that the var is already declared not initialized .so no need to do it again and well you can declare it later at any level or at any line. it is not necessary to do that in the beginning but keep in mind tht it should be declared only once . :-) . i m new at tree house n its gd to get your reply Kevin :-)

Kevin Jervis
Kevin Jervis
2,600 Points

Thanks for the quick response guys. OK so just tried this and getting an error: "Did you use the > symbol to test if a is greater than b?"

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

Charles Wanjohi
Charles Wanjohi
9,235 Points

You need to compare the two variables .Replace 10 with b

var a=10;
var b=20;
if(a>b){
}
Kevin Jervis
Kevin Jervis
2,600 Points

Oh Snap! Got it. Thanks Charles I appreciate the help :o)

ya becz the variable is already initialized so there is no need go reinitialized it .

Kevin Jervis
Kevin Jervis
2,600 Points

That's awesome. Thanks Mehak

you are welcome kevin