Bummer! This is just a preview. You need to be signed in with a Treehouse account to view the entire video.
Ruby Comparison Operators: Greater and Less Than or Equal To3:02 with Jason Seifer
Both the greater and less than operators have equivalents which also check to see whether or not an item is equal to another.
Greater than or equal to operator:
Less than or equal to operator:
1 >= 2 # => false 2 >= 1 # => true 2 >= 2 # => true
Both the greater than and less than operators, have
equivalence to check a quality at the same time.
This will let us test whether or not, one
variable is equal to or greater than another variable.
We write these similarly to how the greater than and less than
operators are written, but we add an equal sign to the end.
Lets take a look at how that works now, using Work spaces.
So, I've launched a Ruby Work space in
Treehouse, and here was are in the console.
Now I've also launched IRB, so here we are inside of IRB.
And I've also created our car one and car two variables
from the last video, which were set to 300 and 500 respectively.
Now let's add another car, we'll say car three,
and that also can go 300 miles per hour.
These are some very fast cars.
Now, if we wanted to use the greater than or equal to operator, we could
say car 1 is greater than or equal to car 3.
And this returns true because car 3 is equal to car 1.
Now, if for some reason car 3's max speed was 301 mile per hour.
We'd say car 1 greater than or equal to car 3, and that returns false.
But, is car 1 less than or equal to car 3?
And it is, now, we can also do two comparisons at a time, so.
Car 1 is greater than or equal to car
3, and that's false, let's clear the screen here.
Now let's take a look at these three variables
again, we've got car 2, car 1 and car 3.
Let's say is car2 greater than, car one, and that is true.
Is car 2 also greater than car 3?
Yes, cuz it can go faster than both, car 1 and car 3.
Now, we can also look at two things at the same time, by going car two.
Greater than car 1, where we can say, and with two ampersand,
car 2 greater than car 3, and that returns true.
And we can do it this way with parentheses
as well, [SOUND] and that whole thing returns true.
We can also do this with or, car 2 is greater than
car 1, or, car 2 car3, and that returns true.
You need to sign up for Treehouse in order to download course files.Sign up