<< Chapter < Page Chapter >> Page >

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 blocks for the variables named Sum and Diff have been dragged from the Variables panel to the center panel and connected to the block that reads when button clicked .

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 panel

The left panel in Image 3 shows the blocks that are exposed when the green button labeled Operators is clicked.

Eleven of those blocks are of the correct shape to fit into the white boxes in the two bottom orange blocks inthe center panel. This means that we could drag any one of those eleven blocks and drop them into those 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.

More blocks of the correct shape

Before leaving the discussion of the left panel in Image 3 , I will explain the behavior of four additional blocks that are of the correct shape forbeing dropped into the white boxes in the variable blocks in the center panel. (The remaining blocks beyond those four deal with strings, which I will ignore for now.)

Random numbers

The block labeled pick random 1 to 10 lets you enter other values in place of 1 and 10. Then this block will deliver a random number withinthat range when it is called upon to do so. Random numbers are often used in game programs to simulate the throwing of dice or the spinning of a wheel offortune.

The modulus

The block labeled mod will produce the modulus of two values when called upon to do so. The modulus of two numbers is the remainder thatresults from dividing one number by another number. You may remember the remainder from when you learned to do long division in elementary school butbefore you learned about decimals.

Questions & Answers

Is there any normative that regulates the use of silver nanoparticles?
Damian Reply
what king of growth are you checking .?
What fields keep nano created devices from performing or assimulating ? Magnetic fields ? Are do they assimilate ?
Stoney Reply
why we need to study biomolecules, molecular biology in nanotechnology?
Adin Reply
yes I'm doing my masters in nanotechnology, we are being studying all these domains as well..
what school?
biomolecules are e building blocks of every organics and inorganic materials.
anyone know any internet site where one can find nanotechnology papers?
Damian Reply
sciencedirect big data base
Introduction about quantum dots in nanotechnology
Praveena Reply
what does nano mean?
Anassong Reply
nano basically means 10^(-9). nanometer is a unit to measure length.
do you think it's worthwhile in the long term to study the effects and possibilities of nanotechnology on viral treatment?
Damian Reply
absolutely yes
how to know photocatalytic properties of tio2 nanoparticles...what to do now
Akash Reply
it is a goid question and i want to know the answer as well
characteristics of micro business
for teaching engĺish at school how nano technology help us
Do somebody tell me a best nano engineering book for beginners?
s. Reply
there is no specific books for beginners but there is book called principle of nanotechnology
what is fullerene does it is used to make bukky balls
Devang Reply
are you nano engineer ?
fullerene is a bucky ball aka Carbon 60 molecule. It was name by the architect Fuller. He design the geodesic dome. it resembles a soccer ball.
what is the actual application of fullerenes nowadays?
That is a great question Damian. best way to answer that question is to Google it. there are hundreds of applications for buck minister fullerenes, from medical to aerospace. you can also find plenty of research papers that will give you great detail on the potential applications of fullerenes.
what is the Synthesis, properties,and applications of carbon nano chemistry
Abhijith Reply
Mostly, they use nano carbon for electronics and for materials to be strengthened.
is Bucky paper clear?
carbon nanotubes has various application in fuel cells membrane, current research on cancer drug,and in electronics MEMS and NEMS etc
so some one know about replacing silicon atom with phosphorous in semiconductors device?
s. Reply
Yeah, it is a pain to say the least. You basically have to heat the substarte up to around 1000 degrees celcius then pass phosphene gas over top of it, which is explosive and toxic by the way, under very low pressure.
Do you know which machine is used to that process?
how to fabricate graphene ink ?
for screen printed electrodes ?
What is lattice structure?
s. Reply
of graphene you mean?
or in general
in general
Graphene has a hexagonal structure
On having this app for quite a bit time, Haven't realised there's a chat room in it.
what is biological synthesis of nanoparticles
Sanket Reply
Got questions? Join the online conversation and get instant answers!
Jobilize.com Reply

Get the best Algebra and trigonometry course in your pocket!

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?