Learn
Conditionals
Comparison Operators

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

1.

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.

2.

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πŸ”€.

3.

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πŸ”€.

Folder Icon

Take this course for free

Already have an account?