02Geek HTML5 and JavaScript, TypeScript, React, Flash, ActionScript online School
Previous VideoNext Video

Rational Operators

We have seen the use of the equality operator and how it is different from the assignment operator. Similarly, Rational Operators also compare two variables and give the result as a Boolean value (true or false.) For Rational Operators we use angular braces or you can say angle brackets or even corner braces. However, we usually to refer them as "greater than symbol >" and "less than symbol <." Likely you now understand what type of symbols we are referring to. We use the same > and < which we used in mathematics in our primary school. In addition there are also two more rational operators which are formed by combining these symbols with the = sign. They are >= and <=, referred as 'greater than or equal to' and 'less than or equal to' respectively.

(>) Greater than Rational Operator

We use this operator to compare the two values or variables to check if one is greater than the other or not. The result is shown in Boolean values. For example, if we consider trace(a>b), the result will be true if 'a' is greater than 'b' and false if 'a' is either less than or equal to 'b'. One more example: trace(7>3), since 7 is greater than 3, the output is given as true. For trace(3>7), the output would be false.

(<) Less than Rational Operator

This is same logic as the one above but reversed. The compiler here checks whether one value is less than the other or not. For example, if we take trace(a<b). the result is true if the value of a is less than b and false if it is equal to or greater than b. If we consider trace(6<7) and trace(5<3), the result is true for the first one and false for the second one.

'Greater than or equal to'(>=) and 'Less than or equal to' (<=) Rational Operators

We have seen how to compare and find whether the first value is less than the second value or greater than the second value. There are cases where we need to find whether the first value is either 'greater than or equal to' to the second value or not. In such a case we use the symbol >=. Similarly, to check if the first value is either 'smaller than or equal to' the second value, we use the symbol <= for that comparison. For example if we take trace(6>=5), the result would be true which meets the greater than condition. If we consider trace(6>=6), the result is still same (true) because it meets the equality condition. Same is the case for trace(5<=6) and trace(6<=6), the result is true for both.

Video Transcript

00:00So the next option we want to talk about we've talked about equation
00:03Let's talk about now about if we want to compare between things that are greater than other things and the way we do that
00:09We use the greater
00:11The greater mark by clicking on your shift dot which would create that type of bracket. I
00:18Would call it a triangle bracket, but I wouldn't know it's the professional terminology to that
00:23So but let's call it greater because that's what it does. So if we wanted to use the greater
00:30Sine we could change our trace here instead of asking if a equals C. Let's check if a is greater than C and
00:39Is is a greater than C is 5 greater than 10 in this scenario?
00:44No, 5 is not greater than 10. So the value that would come back would be false
00:50Now same thing if you wanted to check if B is greater than C is
00:55B greater than C. No B is not greater than C cuz 10 is not greater than 10 10 is equals 10
01:02But 10 is not greater than 10. So that value that would come back would be false
01:07So let's see in a scenario. Let's see one scenario that would come back is true if we would trace out
01:14C greater than a that would come back is true. Why because is 10 greater than 5?
01:24Yes
01:26Trace is greater than 5
01:29So let me just comment down our previous sample
01:32so we could just focus on our samples that we just created now and
01:36We will see that is 5 greater than 10 is a greater than C
01:41No, it's false as B greater than C. No, it's false is 10 greater than 5. Yep. That is true
01:50Okay, so we've seen now how do we could use the greater sample. Let me just duplicate this one
01:57and let's look at smaller than which will be very easy because
02:02Basically the same thing only
02:04The way other way around so instead of a greater than the way we would do smaller than we'd click on the we press on
02:11the shift comma or
02:14smaller
02:16Let's change all these all all these equations to be smaller using our shift
02:21Comma, and let's change it in our traces as well
02:29And let's change it in our traces again. All right, so let's look at it. So is a
02:37Smaller than C. Yes, it is definitely smaller than C. So that would come back is true
02:42Is B smaller than C is 10 smaller than 10?
02:48Now the value would not be true. So it would come back as false is C smaller than a how C equals 10, right?
02:55And a equals 5. So is 10 smaller than 5? That's not true as well. So it's false
03:02So if we run our application just one time to confirm what we already know then we'll see that
03:08It comes back as true the first item because a is smaller than C
03:13Well B is not smaller than C and C is not smaller than a so they come back as false
03:20Very good
03:22Let's look at the next rational operator and that's what these group groups of
03:29Equations are called. They're called rational operators. And if you're afraid you'll forget that term
03:34It's completely fine. No one will be mad at you if you don't remember as long as you remember how to do it
03:40So let's look at our next option. The next option that we want to use is going to be greater or equal and
03:46We could do at the same note we could do or
03:50smaller and equal
03:52So either or but let's start up with our greater or equal and then we're going to go to their smaller or equal
03:58Which is practically the same. So, you know what because we're gonna reuse it. Let's just reuse the code that we created in these
04:06Eight lines, so I'm just gonna copy those eight lines because it's basically the same thing almost and in this one
04:13It would be greater or equal
04:15So let's uncomment here and see
04:20What values would come back is a greater or equal to C
04:25No, a is not greater or equal to C because 5 is not greater or equal to 10
04:30Right, so it would come back as false is B greater or equal to C
04:36Yeah, B is equal to C. So if it's equal to C, then this value would come back is true
04:42Very good. And is C greater or equal to A?
04:49Definitely 10 is greater than 5 so it's greater or equal to 5
04:54So that would be true as well
04:56So let's just run it one time to confirm what we already know
04:59That the first value would come back as false and the next two values would come back as true
05:05Let's look at the last option. We have your up up here
05:12So is a smaller or equal to C a is smaller than C. So that would be true is
05:21B smaller or equal to C
05:24B is equal to C. Right? So that would come back as true is C smaller or equal to a is
05:3610 smaller or equal to 5 not at all. So we come back as false
05:42So if we run our application one more time now
05:45We should see true true false
05:47True true false and we're definitely getting true true false

Ready to Level Up Your Skills?

Join thousands of learners on 02GEEK and start your journey to becoming a coding expert today!

Enroll Now for Free!