<< Chapter < Page | Chapter >> Page > |
As I mentioned earlier, the top script in Image 2 sets the value of each of the four variables to zero when the user clicks the green flag. The codein that script should be completely familiar to you by now and no explanation should be necessary.
The bottom script in Image 2 defines the behavior of the program when the button is clicked. Basically, that code says to set the value of thevariable named Sum to the sum of the contents of the two variables named LeftOperand and RightOperand and to set the value of the variable named Diff to the value of the LeftOperand minus the value of the RightOperand .
That seems straightforward enough. However, the process of constructing that script contains some new material, so I will walk you through the process.
Image 3 shows the state of the development process immediately after
In Image 3 , as it stands now, the variables named Sum and Diff will be set to a value of zero when the user clicks the button. That isn'twhat we want, so we have some more programming to do.
The desired behavior is for the value of the variable named Sum to be set to the sum of the variables named LeftOperand and RightOperand when the user clicks the button. Similarly, we want the value of thevariable named Diff to be set to the difference between those two variables.
The left panel in Image 3 shows the blocks that are exposed when the green button labeled Operators is clicked.
Some of those blocks are of the correct shape to fit into the white boxes in the two bottom orange blocks inthe rightmost panel. This means that we could drag any one of those blocks and drop it into one of the white boxes.
The top four green blocks in the left panel of Image 3 are particularly interesting. They contain the following arithmetic symbols as part of their labels:
These are the symbols that are commonly used for addition, subtraction, multiplication, and division in computer programming. The top two matchwhat you are accustomed to seeing on your hand calculator, but the bottom two probably don't match.
Most programming languages use the * character instead of the X character for multiplication in order to keep the multiplication operator frombeing confused with the letter that uses the X symbol.
Insofar as division is concerned, most computer keyboards don't have a symbol that matches the symbol commonly used for division on hand calculators, so the /character is used instead.
Notification Switch
Would you like to follow the 'Teaching beginners to code' conversation and receive update notifications?