<< Chapter < Page Chapter >> Page >

Image 2. expanded view of the rightmost panel.

Missing image.
Image 2. Expanded view of the rightmost panel.

Initialize the variable values to zero

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.

Define the behavior of the button

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 .

Constructing the script

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

  • the set blocks for the variables named Sum and Diff have been dragged from the Data toolbox to the rightmost panel and connected to the block that reads when this sprite clicked , and
  • the Operators toolbox has been selected.

Image 3. preparing to use the arithmetic operators.

Missing image
Image 3. Preparing to use the arithmetic operators.

Not exactly what we want to happen

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 Operators toolbox

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.

Four arithmetic operators

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.

Use an asterisk for multiplication

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.

Use a forward slash for division

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.

Questions & Answers

what is biology
Hajah Reply
the study of living organisms and their interactions with one another and their environments
AI-Robot
what is biology
Victoria Reply
HOW CAN MAN ORGAN FUNCTION
Alfred Reply
the diagram of the digestive system
Assiatu Reply
allimentary cannel
Ogenrwot
How does twins formed
William Reply
They formed in two ways first when one sperm and one egg are splited by mitosis or two sperm and two eggs join together
Oluwatobi
what is genetics
Josephine Reply
Genetics is the study of heredity
Misack
how does twins formed?
Misack
What is manual
Hassan Reply
discuss biological phenomenon and provide pieces of evidence to show that it was responsible for the formation of eukaryotic organelles
Joseph Reply
what is biology
Yousuf Reply
the study of living organisms and their interactions with one another and their environment.
Wine
discuss the biological phenomenon and provide pieces of evidence to show that it was responsible for the formation of eukaryotic organelles in an essay form
Joseph Reply
what is the blood cells
Shaker Reply
list any five characteristics of the blood cells
Shaker
lack electricity and its more savely than electronic microscope because its naturally by using of light
Abdullahi Reply
advantage of electronic microscope is easily and clearly while disadvantage is dangerous because its electronic. advantage of light microscope is savely and naturally by sun while disadvantage is not easily,means its not sharp and not clear
Abdullahi
cell theory state that every organisms composed of one or more cell,cell is the basic unit of life
Abdullahi
is like gone fail us
DENG
cells is the basic structure and functions of all living things
Ramadan
What is classification
ISCONT Reply
is organisms that are similar into groups called tara
Yamosa
in what situation (s) would be the use of a scanning electron microscope be ideal and why?
Kenna Reply
A scanning electron microscope (SEM) is ideal for situations requiring high-resolution imaging of surfaces. It is commonly used in materials science, biology, and geology to examine the topography and composition of samples at a nanoscale level. SEM is particularly useful for studying fine details,
Hilary
cell is the building block of life.
Condoleezza Reply
Got questions? Join the online conversation and get instant answers!
Jobilize.com Reply

Get Jobilize Job Search Mobile App in your pocket Now!

Get it on Google Play Download on the App Store Now




Source:  OpenStax, Teaching beginners to code. OpenStax CNX. May 27, 2013 Download for free at http://cnx.org/content/col11498/1.20
Google Play and the Google Play logo are trademarks of Google Inc.

Notification Switch

Would you like to follow the 'Teaching beginners to code' conversation and receive update notifications?

Ask