# 0.7 Phy1040: scientific notation and significant figures  (Page 5/8)

 Page 5 / 8

Please copy the JavaScript code shown in Listing 1 into an html file and open the file in your browser.

Listing 1 . An exercise involving addition.
```<!-- File JavaScript01.html --><html><body><script language="JavaScript1.3">//Compute and display the sum of three // numbersvar a = 169.01 var b = 0.00356var c = 385.293 var sum = a + b + cdocument.write("sum = " + sum + "</br>") //Round the sum to the correct number// of digits to the right of the decimal // point.var round = sum.toFixed(2) document.write("round = " + round + "</br>") //Display a final line as a hedge against// unidentified coding errors. document.write("The End")</script></body></html>```

Screen output

When you open the html file in your browser, the text shown in Figure 2 should appear in your browser.

Figure 2 . Screen output from Listing #1.
```sum = 554.30656 round = 554.31The End```

The code in Listing 1 begins by declaring three variables named a , b , and c , adding them together, and displaying the sum in the JavaScript default format in the browser window.

Too many decimal digits

As you can see from the first line in Figure 2 , the result is computed and displayed with eight decimal digits, five of which are to the right of thedecimal point. We know, however, from rule #1 , that we should present the result rounded to a precision of two digits to theright of the decimal point in order to match the least precise of the numbers included in the sum. In this case, the value stored in the variable named a is the least precise.

Correct the problem

The code in Listing 1 calls a method named toFixed on the value stored in the variable sum passing a value of 2 as a parameter to the method. This method returns the value from sum rounded to two decimal digits. The returned value is stored in the variablenamed round . Then the script displays that value as the second line of text in Figure 2 .

The output text that reads "The End"

There is a downside to using JavaScript (as opposed to other programming languages such as Java). By default, if there is a codingerror in your script, there is no indication of the error in the output in the main browser window.Instead, the browser simply refuses to display some or all of the output that you are expecting to see. (Remember, I told you that JavaScript is not my favoriteprogramming language, but it is probably the most accessible for blind students who have no programming experience.)

Put a marker at the end

Writing the script in such a way that a known line of text, such as "The End" will appear following all of the other output won't solve coding errors.However, if it doesn't appear, you will know that there is a coding error and some or all of the output text may be missing.

JavaScript and error consoles

I explained how you can open a JavaScript console in the Google Chrome browser or an error console in the Firefox browser in an earlier module titled JavaScript for Blind Students . While the diagnostic information provided in those consoles is limited, it will usually indicate the line number in the source codewhere the programming error was detected. Knowing the line number will help you examine the code and fix the error.

what is the stm
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?
what is a peer
What is meant by 'nano scale'?
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
what is Nano technology ?
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?
what king of growth are you checking .?
Renato
What fields keep nano created devices from performing or assimulating ? Magnetic fields ? Are do they assimilate ?
why we need to study biomolecules, molecular biology in nanotechnology?
?
Kyle
yes I'm doing my masters in nanotechnology, we are being studying all these domains as well..
why?
what school?
Kyle
biomolecules are e building blocks of every organics and inorganic materials.
Joe
anyone know any internet site where one can find nanotechnology papers?
research.net
kanaga
sciencedirect big data base
Ernesto
Introduction about quantum dots in nanotechnology
what does nano mean?
nano basically means 10^(-9). nanometer is a unit to measure length.
Bharti
do you think it's worthwhile in the long term to study the effects and possibilities of nanotechnology on viral treatment?
absolutely yes
Daniel
how to know photocatalytic properties of tio2 nanoparticles...what to do now
it is a goid question and i want to know the answer as well
Maciej
Abigail
for teaching engĺish at school how nano technology help us
Anassong
How can I make nanorobot?
Lily
Do somebody tell me a best nano engineering book for beginners?
there is no specific books for beginners but there is book called principle of nanotechnology
NANO
how can I make nanorobot?
Lily
what is fullerene does it is used to make bukky balls
are you nano engineer ?
s.
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.
Tarell
what is the actual application of fullerenes nowadays?
Damian
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.
Tarell
Got questions? Join the online conversation and get instant answers!