Saturday, September 12, 2015

Order of Operations in Scratch


   Order of Operations is one concept in the traditional mathematics curriculum that programmers quickly forget. You will never see code written to evaluate expressions like this, 42 – 6 x 2 ÷ 4 x 3 + 5.
   So, how are operations handled in Scratch?
   Look at the green Operators menu in Scratch. Note that the four arithmetic operators, the random number picker, string operators (join, letter, length), mod, round, and square root operators are rounded at each end. The relational (<. =, >) and Boolean operators (and, or, not) are pointed at each end.
   The rounded ends represents parenthesis.
   Will this block evaluate as 9 or 7?
   If you look carefully you will see that the parenthesis tell us that the block will evaluate as 7.
   To build the expression, drop the multiplication block into the addition block. The white circle can be thought of as a set of  parenthesis ( ).

   If you build the expression and then click on it, it will report 7.

   Order of operations are very simple in Scratch.
Think parenthesis!