Computers are incredible at doing calculations. Now that we have declared variables, let’s use them with arithmetic operators to calculate things!
Here are some arithmetic operators:
%modulo (divides and gives the remainder)
var score = 0 // score is 0 score = 4 + 2 // it is now 6 score = score - 2 // it is now 4 score = 4 * 2 // it is now 8 score = 4 / 2 // and now 2 score = 5 % 2 // and now 1
Note: The order of operations can be specified using parentheses. For example, the use of parentheses in
score = 4 * (2 + 1) sets score equal to
4 * 3 rather than
8 + 1.
In the code editor, we have already declared and initialized a variable called
Declare a new variable named
tip and give it the value of
amount multiplied by
Now print out
How much is the tip?