<< Chapter < Page | Chapter >> Page > |
Rearranging the terms
We can rearrange the terms and rewrite this equation as
distance = (63360 * inch * 1*foot * 1 * mile)/(12*inch*5280*foot)
Canceling like terms
Canceling out like terms in the numerator and denominator leaves us with
distance = (63360*mile)/(12*5280)
Doing the arithmetic, we get
distance = 1*mile
(Obviously, I started out with a set of numbers that were designed to cause the final answer to be one mile, but that was simply for convenience.)
There you have it
You have seen a detailed procedure for converting from a distance expressed in paces (for a specific individual) to the same distanceexpressed in miles. Obviously, once you understand the overall procedure, you could omit and/or combine some of the steps to simplify the process.
Let's write, execute, and analyze a script that solves the same problem.
The objective of the script is to convert a distance of 2112 paces to a distance in miles where it is given that
Please copy the code from Listing 1 into an html file and open the file in your browser.
Listing 1 . Convert from paces to miles.
>!-- File JavaScript01.html ------------------------------>>html>>body>>script language="JavaScript1.3">var d = 2112 //distance, units = paces
document.write("d = " + d + " paces" + "<br/>")
var d2 = 3000 //distance, units = inchesvar d3 = 100 //distance, units = paces
var f1 = d2/d3 //factor, units = inches/pacedocument.write(
"f1 =" + f1 + " inches/pace" + "<br/>")
//pace*inch/pace = inchvar d = d *f1 //distance, units = inches
document.write("d = " + d + " inches" + "<br/>")
var f2 = 1/12 //factor, units = feet/inchdocument.write(
"f2 = " + f2 + " feet/inch" + "<br/>")
//inch*feet/inch = feetvar d = d *f2 //distance, units = feet
document.write("d = " + d + " feet" + "<br/>")
var f3 = 1/5280 //factor, units = miles/footdocument.write(
"f3 = " + f3 + " miles/foot" + "<br/>")
//feet*mile/feet = milevar d = d *f3 //distance, units = miles
document.write("d = " + d + " mile" + "<br/>")
//Now reverse the process using reciprocals//(pace/inch)*(inch/foot)*(foot/mile) = pace/mile
var f4 =(1/f1)*(1/f2)*(1/f3) //factor, units = paces/miledocument.write(
"f4 = " + f4 + " paces/mile" + "<br/>")
//miles*paces/mile = pacesvar d = d *f4 //distance, units = paces
document.write("d = " + d + " paces" + "<br/>")
document.write("The End")>/script>>/body>>/html>
Screen output
When you open the html file in your browser, the text shown in Figure 5 should appear in your browser window.
Figure 5 . Screen output for Listing #1. |
---|
d = 2112 paces
f1 =30 inches/paced = 63360 inches
f2 = 0.08333333333333333 feet/inchd = 5280 feet
f3 = 0.0001893939393939394 miles/footd = 1 mile
f4 = 2112 paces/miled = 2112 paces
The End |
Discuss the output first
Let's begin our discussion with the screen output shown in Figure 5 and then go back and examine the code that produced that output.
Figure 5 begins with a distance (labeled d ) expressed in units of paces. The value is 2112 paces, which is the distance from your home to your school discussed earlier.
Notification Switch
Would you like to follow the 'Game 2302 - mathematical applications for game development' conversation and receive update notifications?