When you add, subtract, multiply, or divide, the +, -, *, and / (for divide) symbols are called *operators*.

You may know from math that some operators are always done before others (for example, the PEMDAS mnemonic). For example:

1 |
2 + 3 * 4 = 14 (not 20) |

because multipication is always done before addition. *Processing* is the same way. Multiplication and division are always done before addition and subtraction. You can use parenthesis to change the order. Operations in parenthesis are always done first. For example:

1 |
(2 + 3) * 4 = 20 (parenthesis first) |

Here are some examples. Make sure you understand why each variable has the stated value. Ask if you don’t:

1 2 3 4 5 6 7 8 |
var x, y, a, b; x = 5; a = 10; b = 20; y = a + b; // y equals 30 x = (y - 10) * 20; // before, x equalled 5, now x equals 400 x = x * 5; // now x = 2000 |

The next two activities will touch on operator precedence though they are mostly about following the value of variables. Remember the computer will execute one line at a time. If variable values are changed, the computer will use the most recent value of the variable.

Complete Activity 12

Complete Activity 13