In Math class, we might have been asked to solve equations like:
2 * 6 + 10 / 2
If we read out our equation from left to right we might think that the answer is 11
. However, itβs actually 17
because we have to follow a specific order of operations. In the United States, thereβs a helpful mnemonic called PEMDAS that helps us remember to the order:
2 * 6
, which is12
- Then we have to divide! So
10 / 2
is5
. - Lastly, we add
12
and5
to get17
!
But wouldnβt it be nice if someone put in parentheses to group together expressions for us to evaluate? That way we donβt have to remember the specific ordering. Our neatly grouped expression would be:
(2 * 6) + (10 / 2)
The insertion of parentheses makes it clear which operations are done first. Emojicode also has its own order of operations that determines the order in which expressions are evaluated. But, we can control the order using the emoji equivalent of parentheses, ( )
, π€ π€
. When we translate our math equation to Emojicode, we get:
π€ 2 βοΈ 6 π€ β π€ 10 β 2 π€
Using π€ π€
, we make it clearer for which expressions go together and we decide the order of expressions.
Instructions
Letβs use π€ π€
to make our first conditional easier to read.
Currently, we have the conditional:
βͺοΈ offer βΆοΈ minPrice π€ offer βοΈ maxPrice π π π€Offer accepted!π€βοΈ π
In the condition, add a set of π€ π€
around offer βΆοΈ minPrice
and another set of π€ π€
around offer βοΈ maxPrice
. This way we have a clear grouping of expressions.
In the second conditional, the condition looks like:
π π π π€ π
As is, the condition evaluates to π
. We need to group together an expression inside the condition, using a single set of π€ π€
, to make the condition evaluate to π
.
The last expression is stored in a variable mathPuzzle
that reads as:
10 βοΈ 6 β 2 β 2
It currently evaluates to 59
, but we want it to evaluate to 20
instead. Add a single set of π€ π€
to make this happen.