<< Chapter < Page Chapter >> Page >

An exercise involving addition

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.

Questions & Answers

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
anyone know any internet site where one can find nanotechnology papers?
Damian Reply
research.net
kanaga
sciencedirect big data base
Ernesto
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.
Bharti
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
Daniel
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
Maciej
characteristics of micro business
Abigail
for teaching engĺish at school how nano technology help us
Anassong
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
NANO
what is fullerene does it is used to make bukky balls
Devang Reply
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
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.
Virgil
is Bucky paper clear?
CYNTHIA
carbon nanotubes has various application in fuel cells membrane, current research on cancer drug,and in electronics MEMS and NEMS etc
NANO
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.
Harper
Do you know which machine is used to that process?
s.
how to fabricate graphene ink ?
SUYASH Reply
for screen printed electrodes ?
SUYASH
What is lattice structure?
s. Reply
of graphene you mean?
Ebrahim
or in general
Ebrahim
in general
s.
Graphene has a hexagonal structure
tahir
On having this app for quite a bit time, Haven't realised there's a chat room in it.
Cied
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
Berger describes sociologists as concerned with
Mueller 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, 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