Consider the making of hard-boiled π₯. We need both: boiling water and an egg. If even one ingredient is missing, we canβt make it. So we should check for both conditions before we flex our culinary skills.
In programming, we also have to consider multiple conditions at the same time before executing code. Thatβs where logical operators, like the π€
operator, become extremely useful. The π€
operator checks if two expressions are π
and returns a single π
value. If the first expression π
AND the second expression is π
, then it returns π
β otherwise, it returns π
.
Hereβs a table that shows the possible combinations of π
values in usage with π€
:
Expression | Evaluates to |
---|---|
π π€ π |
π |
π π€ π |
π |
π π€ π |
π |
π π€ π |
π |
Notice that only the first expression (π π€ π
) evaluates to π
.
Translating our π₯ scenario to code, we get:
π β‘οΈπ hasEgg π β‘οΈπ hasBoilingWater βͺοΈ hasEgg π€ hasBoilingWater π π π€We can make a hard-boiled π₯!π€βοΈ π π π π π€The conditions aren't right...π€βοΈ π π Prints: We can make a hard-boiled π₯!
Letβs use the π€
in our own code!
Instructions
We have two variables,learningEmojicode
and isDedicated
, both have a value of π
.
Create a βͺοΈ
statement that checks both learningEmojicode
and isDedicated
. In the code block(ππ
), use a πβοΈ
to print out the string: π€Becoming a π» master!π€
.