Learn
Variables
Arithmetic Operations
Computers are incredible at doing calculations. Now that we have declared variables, letโs use them with arithmetic operators to calculate things!
Emojicode supports arithmetic operators for:
โ
: additionโ
: subtractionโ๏ธ
: multiplicationโ
: division๐ฎ
: modulo (divides and gives the remainder)
For example:
4 โ 2 โก๏ธ score1 ๐ญ scores1 is 6 4 โ 2 โก๏ธ score2 ๐ญ scores2 is 2 4 โ๏ธ 2 โก๏ธ score3 ๐ญ scores3 is 8 4 โ 2 โก๏ธ score4 ๐ญ scores4 is 2 4 ๐ฎ 2 โก๏ธ score5 ๐ญ scores5 is 0
Here, we are doing some arithmetic operations and storing the results in five different constants.
Instructions
1.
In the code editor, we have already declared and initialized a variable called amount
.
Declare a new variable named tip
and give it the value of amount
multiplied by 0.2
.
Note: There are quite a few variations of xโs in the emoji picker. Make sure to use โ๏ธ
.
2.
Use string interpolation to print a message that says:
The tip is $[tip]
Where [tip]
is the value of the tip
constant.