Bummer! This is just a preview. You need to be signed in with a Basic account to view the entire video.
Start a free Basic trial
to watch this video
Both the greater and less than operators have equivalents which also check to see whether or not an item is equal to another.
Code Samples
Greater than or equal to operator:
>=
Less than or equal to operator:
<=
Examples:
1 >= 2 # => false
2 >= 1 # => true
2 >= 2 # => true

0:00
Both the greater than and less than operators, have

0:03
equivalence to check a quality at the same time.

0:07
This will let us test whether or not, one

0:10
variable is equal to or greater than another variable.

0:15
We write these similarly to how the greater than and less than

0:18
operators are written, but we add an equal sign to the end.

0:22
Lets take a look at how that works now, using Work spaces.

0:27
So, I've launched a Ruby Work space in

0:29
Treehouse, and here was are in the console.

0:33
Now I've also launched IRB, so here we are inside of IRB.

0:39
And I've also created our car one and car two variables

0:43
from the last video, which were set to 300 and 500 respectively.

0:50
Now let's add another car, we'll say car three,

0:53
and that also can go 300 miles per hour.

0:55
These are some very fast cars.

0:59
Now, if we wanted to use the greater than or equal to operator, we could

1:04
say car 1 is greater than or equal to car 3.

1:09
And this returns true because car 3 is equal to car 1.

1:17
Now, if for some reason car 3's max speed was 301 mile per hour.

1:23
We'd say car 1 greater than or equal to car 3, and that returns false.

1:32
But, is car 1 less than or equal to car 3?

1:35
And it is, now, we can also do two comparisons at a time, so.

1:42
Car 1 is greater than or equal to car

1:47
3, and that's false, let's clear the screen here.

1:52
Now let's take a look at these three variables

1:54
again, we've got car 2, car 1 and car 3.

1:58
Let's say is car2 greater than, car one, and that is true.

2:07
Is car 2 also greater than car 3?

2:12
Yes, cuz it can go faster than both, car 1 and car 3.

2:18
Now, we can also look at two things at the same time, by going car two.

2:25
Greater than car 1, where we can say, and with two ampersand,

2:33
car 2 greater than car 3, and that returns true.

2:40
And we can do it this way with parentheses

2:44
as well, [SOUND] and that whole thing returns true.

2:48
We can also do this with or, car 2 is greater than

2:54
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