<< Chapter < Page Chapter >> Page >
  • The function keyword
  • The function name: getHalf
  • An argument list containing a single parameter named incomingParameter
  • A function body enclosed in a pair of matching curly brackets

Simpler than the surface area of a sphere

The function named getHalf is somewhat simpler than one that could be used to calculate the surface area of a sphere, but the basic conceptis the same. This function expects to receive one parameter.

The code in the body of the function uses the division operator, "/", to divide the value of the incoming parameter by 2. Then it returns the result ofthat calculation. When the function returns, the return value will replace the call to the function in the calling script.

Two calls to the function

The function is called twice in the body of the script in Listing 2 , passing a different value for the parameter during each call.

Each call to the function named getHalf is embedded as one of the elements in theargument list following document.write .

write is also a function

Although I didn't mention this earlier because you weren't ready for it yet, write is also the name of a function. However, the write function is predefined in JavaScript and we can use it to display information in the browser window without having to defineit first.

(Actually, write is a special kind of a function that we call a method , but you don't need to worry about that unless you want to dig much deeper into theobject-oriented aspects of JavaScript.)

Two calls to the getHalf function

The script in Listing 2 calls the function named getHalf twice in two different locations, each of which is embedded in the argument listof a call to the write method. Each call passes a different parameter value to the getHalf function.

The order of operations

When a call to a function or method (such as the call to the write method) includes a call to another function or method in its argument list, thecall to the function in the argument list must be completed before the call can be made to the function having the argument list. Therefore in each of these twocases, the call to the getHalf function must be completed before the call to the write method can be executed.

Output from script in Listing 2

Each call to the getHalf function returns a value that is half the value of its incoming parameter.

As I mentioned earlier, when the function returns, the returned value replaces the call to the function. Therefore, ineach case, the returned value from the call to the getHalf function becomes part of the argument list for the write method before that method is called. This causes the two calls to the write method in Listing 2 to display the values returned from the calls to the getHalf function as shown in Figure 2 .

Figure 2 . Output from script in Listing 2.
Call getHalf for 10.6 Half is: 5.3Call getHalf again for 12.3 Half is: 6.15

Good programming design

It is a principle of good programming design that each function should perform only one task, and should perform it well. The task performed by thefunction named getHalf is to calculate and return half the value that it receives, and it does that task very well.

Questions & Answers

where we get a research paper on Nano chemistry....?
Maira Reply
what are the products of Nano chemistry?
Maira Reply
There are lots of products of nano chemistry... Like nano coatings.....carbon fiber.. And lots of others..
learn
Even nanotechnology is pretty much all about chemistry... Its the chemistry on quantum or atomic level
learn
Google
da
no nanotechnology is also a part of physics and maths it requires angle formulas and some pressure regarding concepts
Bhagvanji
Preparation and Applications of Nanomaterial for Drug Delivery
Hafiz Reply
revolt
da
Application of nanotechnology in medicine
what is variations in raman spectra for nanomaterials
Jyoti Reply
I only see partial conversation and what's the question here!
Crow Reply
what about nanotechnology for water purification
RAW Reply
please someone correct me if I'm wrong but I think one can use nanoparticles, specially silver nanoparticles for water treatment.
Damian
yes that's correct
Professor
I think
Professor
Nasa has use it in the 60's, copper as water purification in the moon travel.
Alexandre
nanocopper obvius
Alexandre
what is the stm
Brian Reply
is there industrial application of fullrenes. What is the method to prepare fullrene on large scale.?
Rafiq
industrial application...? mmm I think on the medical side as drug carrier, but you should go deeper on your research, I may be wrong
Damian
How we are making nano material?
LITNING Reply
what is a peer
LITNING Reply
What is meant by 'nano scale'?
LITNING Reply
What is STMs full form?
LITNING
scanning tunneling microscope
Sahil
how nano science is used for hydrophobicity
Santosh
Do u think that Graphene and Fullrene fiber can be used to make Air Plane body structure the lightest and strongest. Rafiq
Rafiq
what is differents between GO and RGO?
Mahi
what is simplest way to understand the applications of nano robots used to detect the cancer affected cell of human body.? How this robot is carried to required site of body cell.? what will be the carrier material and how can be detected that correct delivery of drug is done Rafiq
Rafiq
if virus is killing to make ARTIFICIAL DNA OF GRAPHENE FOR KILLED THE VIRUS .THIS IS OUR ASSUMPTION
Anam
analytical skills graphene is prepared to kill any type viruses .
Anam
Any one who tell me about Preparation and application of Nanomaterial for drug Delivery
Hafiz
what is Nano technology ?
Bob Reply
write examples of Nano molecule?
Bob
The nanotechnology is as new science, to scale nanometric
brayan
nanotechnology is the study, desing, synthesis, manipulation and application of materials and functional systems through control of matter at nanoscale
Damian
Is there any normative that regulates the use of silver nanoparticles?
Damian Reply
what king of growth are you checking .?
Renato
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
?
Kyle
yes I'm doing my masters in nanotechnology, we are being studying all these domains as well..
Adin
why?
Adin
what school?
Kyle
biomolecules are e building blocks of every organics and inorganic materials.
Joe
how did you get the value of 2000N.What calculations are needed to arrive at it
Smarajit Reply
Privacy Information Security Software Version 1.1a
Good
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, 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