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

What have I done wrong?

Is my conditional statement correct?

script.js
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'); }
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>
Zack Lee
Zack Lee
Courses Plus Student 17,662 Points

what are you trying to achieve? do you get an error? do you not recieve an alert?

James Tew
James Tew
2,774 Points

Your conditional statement will return the else alert as 'a' is not greater than 'b'.

If you want it to return the if statement, you'll need to amend your code to this:

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

2 Answers

Steven Parker
Steven Parker
231,271 Points

The challenges are very picky about output strings. The issue is the space inside the string before the letter "a". Remove that from both strings and you will pass the challenge.

The space between the function name and the parenthesis is not an issue, though it would be a "best practice" to not have one there either.

Thank you. that was the problem.

Danielle Schorfheide
Danielle Schorfheide
2,737 Points

I just did this one myself. The only potential issue I can see is the space between "alert" and the opening parentheses. I'm not certain if that is proper syntax. Maybe it is causing an error?

Zack Lee
Zack Lee
Courses Plus Student 17,662 Points

white space should have no effect on the syntax. I just ran the code myself and it alerted me that "a was less than b" which is correct. I'm not sure what the issue is because it works fine for me.