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 trialWalter Cortez
4,071 PointsCan't figure this one out...Please help. Thank you!
What am I doing wrong here?
var a = 10;
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>
john larson
16,594 Points:D
2 Answers
john larson
16,594 PointsHi 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');
}
john larson
16,594 Pointsok 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
4,071 PointsThis 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
3,727 PointsHello, 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
4,071 PointsThat 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!
Walter Cortez
4,071 PointsWalter Cortez
4,071 Pointshttps://w.trhou.se/moe3d7uvsh