<< Chapter < Page Chapter >> Page >

Arithmetic operators

The division operation in Listing 2 introduced the use of arithmetic operators.

In computer programming jargon, we speak of operators and operands. Operators operate on operands.

As a real-world example, if you were to go to the hospital for knee surgery, the surgeon would be the operator and you would be the operand . The surgeon would operate on you.

Binary operators

The operators that we will use in the modules in this collection will usually be restricted to those that have two operands, a left operand and a right operand . (Operators with two operands are commonly called binary operators .)

In the function named getHalf in Listing 2 , the "/" character is the division operator. The left operand is incomingParameter and the right operand is 2 . The result is that the incoming parameteris divided by the right operand (2).

Binary arithmetic operators

The binary arithmetic operators supported by JavaScript are shown in Figure 3 .

Figure 3 . Binary arithmetic operators.
+ Addition: Adds the operands - Subtraction: Subtracts the right operand from the left operand* Multiplication: Multiplies the operands / Division: Divides the left operand by the right operand% Modulus: Returns integer remainder of dividing the left operand by the right operand

We will use these operators extensively as we work through the physics exercises in future modules.

Sequence

Of the four items listed under Structured programming earlier, the simplest one is sequence .

The concept of sequence in structured programming simply means that code statements can be executed in sequential order. Listing 2 provides a good example of the sequential execution of statements. The code in Listing 2 shows four sequential statements that begin with document.write.

Selection

The next item that we will discuss from the list under Structured programming is selection . While not as simple as sequence , selection is something that you probably do many times each day without even thinking about it. Therefore, once you understand it, it isn'tcomplicated.

General syntax for selection statement

The general syntax for a selection statement (often called an if-else statement) is shown in Figure 4 .

Figure 4 . General syntax for selection statement.
if(conditional expression is true){ execute code}else{//optional execute alternative code}//end selection statement

A selection statement performs a logical test that returns either true or false. Depending on the result, specific code is executed to control thebehavior of the script.

A real-world analogy

Figure 5 shows a real-world analogy of a selection statement that you might make on your day off.

Figure 5 . Real-world analogy of a selection statement.
if(it is not raining){ Play tennisGo for a walk Relax on the beach}else{//optional Make popcornWatch TV }//end selection statement

In this analogy, you would check outside to confirm that it is not raining. If the condition is true (meaning that it isn't raining), you wouldplay tennis, go for a walk, and then relax on the beach. If it is raining, (meaning that the test condition is false), you would make some popcorn and relax in front of theTV.

Questions & Answers

what is phylogeny
Odigie Reply
evolutionary history and relationship of an organism or group of organisms
AI-Robot
ok
Deng
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
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, Accessible physics concepts for blind students. OpenStax CNX. Oct 02, 2015 Download for free at https://legacy.cnx.org/content/col11294/1.36
Google Play and the Google Play logo are trademarks of Google Inc.

Notification Switch

Would you like to follow the 'Accessible physics concepts for blind students' conversation and receive update notifications?

Ask