In addition to π
operator, Emojicode also offers other comparison operators to expand our use cases!
Hereβs a list of the comparison operators:
Operator | Operation |
---|---|
βοΈ | Less than |
βΆοΈ | Greater than |
βοΈπ | Less than or equal to |
βΆοΈπ | Greater than or equal to |
Like the π
operator, the listed operators all compare two values and returns a π
or π
value. For example:
2 βοΈ 5 π π
We can read the expression above as a question, βis 2
less than 5
?β Since the answer is yes, then π
is returned. Below are a few more examples to read through to understand the use of comparison operators:
4 βοΈ 4 π π 10 βΆοΈ 5 π π 10.6 βοΈπ 10.6 π π 3.14 βΆοΈπ 4 π π
Once youβre ready, tackle the steps in this exercise!
Instructions
Imagine weβre in a theme park that has different attractions. Each attraction has a height requirement (in centimeters) as shown by the variables hurlyWhirlyMinHeight
and tinyHouseMaxHeight
.
Weβll be adding in checks to see if our visitor can safely enjoy these attractions, but first, we need a visitor!
Type out your height (in centimeters) and use β‘οΈ
to assign it to a variable called myHeight
.
As we can tell from hurlyWhirlyMinHeight
, the Hurly-Whirly ride has a minimum height of 120
cm.
Create an βͺ
statement that checks if myHeight
is less than to hurlyWhirlyMinHeight
. Inside the ππ
block, add a πβοΈ
statement that prints out π€You must be taller than 120cm to rideπ€
.
Our other attraction, the Tiny House has a maximum height of 214
cm (as seen by tinyHouseMaxHeight
).
Create another βͺ
statement that checks if myHeight
is greater than or equal to tinyHouseMaxHeight
. Inside the ππ
block, add a πβοΈ
statement that prints out π€You must be 214cm or shorter to enterπ€
.