Learn
Conditionals
The πŸ™Œ Operator

Let’s now expand the use of our conditionals to account for other types like: πŸ”€, or πŸ”’, or πŸ’―! But there’s a question of, β€œhow do we convert the types πŸ”€,πŸ”’, and πŸ’― to πŸ‘Œ values?” Well, that’s where the πŸ™Œ comes in!

πŸ™Œ compares two values, one on its left side and one on its right side, to see if they have the same value. The entire piece of code is an expression, we can think of expressions as code that evaluates to a value. In this case, the expression evaluates back to a πŸ‘ or πŸ‘Ž value.

Let’s see a few examples:

100 πŸ™Œ 100 πŸ’­ Evaluates to: πŸ‘ 100 πŸ™Œ 101 πŸ’­ Evaluates to: πŸ‘Ž 32.1 πŸ™Œ 32 πŸ’­ Evaluates to: πŸ‘Ž 4.2 πŸ™Œ 4.2 πŸ’­ Evaluates to: πŸ‘ πŸ”€AπŸ”€ πŸ™Œ πŸ”€AπŸ”€ πŸ’­ Evaluates to: πŸ‘ πŸ”€AπŸ”€ πŸ™Œ πŸ”€BπŸ”€ πŸ’­ Evaluates to: πŸ‘Ž πŸ”€AπŸ”€ πŸ™Œ πŸ”€aπŸ”€ πŸ’­ Evaluates to: πŸ‘Ž

Read through the examples and make sure you understand how the comparison works. Let’s also take a look at the πŸ™Œ usage in a conditional:

β†ͺ️ πŸ”€cokeπŸ”€ πŸ™Œ πŸ”€pepsiπŸ”€ πŸ‡ πŸ˜€ πŸ”€They're the same thingπŸ”€β—οΈ πŸ‰ πŸ™… πŸ‡ πŸ˜€ πŸ”€They're NOT the sameπŸ”€β—οΈ πŸ‰

In the example above, our condition is the expression πŸ”€cokeπŸ”€ πŸ™Œ πŸ”€pepsiπŸ”€. Since the strings are not the same, they're NOT the same is printed to the terminal.

Instructions

1.

Under the declared variables enteredPIN and correctPIN, add a β†ͺ️ statement that checks if enteredPIN and correctPIN are the same string using the πŸ™Œ operator.

Inside the πŸ‡ πŸ‰ block, add a πŸ˜€β—οΈ to print out πŸ”€Access grantedπŸ”€.

2.

We should also add an else statement using πŸ™…. Inside this πŸ‡ πŸ‰ block, use πŸ˜€β—οΈ to print out πŸ”€Access deniedπŸ”€.

Folder Icon

Take this course for free

Already have an account?