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 trialKevin Jervis
2,600 PointsConditional 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.
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;
<!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
9,235 PointsRemove the var inside the if statement.It should be:
if(a>10){
}
you arent supposed to redeclare variable a in the if condition
Mehak Bhola
262 Pointsand 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
2,600 PointsThanks 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
9,235 PointsYou need to compare the two variables .Replace 10 with b
var a=10;
var b=20;
if(a>b){
}
Kevin Jervis
2,600 PointsOh Snap! Got it. Thanks Charles I appreciate the help :o)
Mehak Bhola
262 Pointsya becz the variable is already initialized so there is no need go reinitialized it .
Kevin Jervis
2,600 PointsThat's awesome. Thanks Mehak
Mehak Bhola
262 Pointsyou are welcome kevin
Regena Koeshall
Front End Web Development Techdegree Graduate 21,143 PointsRegena Koeshall
Front End Web Development Techdegree Graduate 21,143 Pointsjust move your entire if statement after the variables and you can remove the <p> tags from inside your alerts