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 trialSaad Shah
4,006 PointsConditional statement
Hi Treehousers. This is a very simple exercise but I can't seem to get the syntax right. What am I missing conceptually?
var a = 10;
var b = 20;
var c = 30;
if ('var a' > 'var b') {
alert ("a is greater than b");
} else {
alert ("a is not greater than b");
}
<!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>
2 Answers
Christopher Debove
Courses Plus Student 18,373 PointsHi there! The problem in your code is that you're comparing the two strings "var a" and "var b".
What you want to compare is the value of your variable "a" and your variable "b".
So inside your if statement : a > b
is what you need (Is the value of "a" is greater than the value of "b")
andren
28,558 PointsYour issue seems to be that you are confused about how you are meant to reference a variable. Quotes (single or double) are only used when creating a string. They are not used when referencing a variable. Additionally the var
keyword is only used when creating a variable, not when referencing an existing one.
So you have to remove the quotes, and the var
keyword like 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");
}
Doing that will fix your code. As everything else you have written is correct.
Saad Shah
4,006 PointsWorked, thanks for the explanation!
Saad Shah
4,006 PointsSaad Shah
4,006 PointsWorked like a charm, thanks!