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

Walter Cortez
Walter Cortez
4,071 Points

Can't figure this one out...Please help. Thank you!

What am I doing wrong here?

script.js
var a = 10;
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>

:D

2 Answers

Hi Walter, I don't know what you were doing wrong cause I didn't see your answer. But this worked for me.

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

ok found it

var a = 10;
var b = 20;
var c = 30;

//<=== is not a comparison operator in JS...I don't think.
if ( answer <=== '20') { //also "answer" is not part of the comparison
  alert('a is greater than b'); //we are only comparing a and b
} else {
 alert('a is not greater than b'); 
} 
Walter Cortez
Walter Cortez
4,071 Points

This is great! Now, I understand...I was having trouble understanding the Task I found myself reading it a couple of times and somehow, it still didn't make sense to me.

Thank you very much John! Happy coding!!!

Mauro Teixeira
Mauro Teixeira
3,727 Points

Hello, what exactly are you trying to do? I took a look at the code in you workspace (which is different from the one you posted) and the first thing I noticed was that you <script> tag importing your js script is out of place. It's not that it won't work, it's just that you don't usually import a script in the middle of your HTML code. It is good practice to not mix the two, so you should do your <script src="quiz.js"></script> either in the <head> or at the beginning or end of <body>, try no to put them in the middle of the html components.

Also, in your code you define variables a, b and c, and then you try to compare "answer" with one of the variables. Of course, this "answer" is not defined, so the result of your code won't be what you expect. Were you maybe trying to compare a with b?

Also, the comparison you are trying to make is not correct. Instead of <===, you should actually use <=.

Moreover, you first define your variables a, b and c as integers, but then you try to compare them with a string. I believe you are trying to do, for example, if (a <= 20) and not if (a <=== '20').

As you can see, there are a lot of issues with your code. Can you tell us what you are trying to achieve?

Walter Cortez
Walter Cortez
4,071 Points

That is great advice Mauro! I was having trouble understanding the Task. I will keep your advice in mind next time I code!

Thank you, Happy coding!