CSGNetwork.com Free Information

Sample Problem in JavaScript and HTML
To Calculate Cubic Feet and Optional Cost
In a Southern California Real-Life Situation

Problem and Instructions

This converter requires the use of Javascript enabled and capable browsers. This calculator is to serve three purposes. Hopefully, you will find this interesting (at least as interesting as a problem like this can be) and challenging. You may "steal" this sourcecode if you wish. We ask that you leave the credits in place.

Purpose 1. To give an example of JavaScript programming to do simple math within HTML pages. Over the last few months, we have gotten hundreds of E-Mail requests for a section to be added to our site to show programming language examples and give a tutorial on HTML programming and JavaScript programming. We have decided to add that to our list of things to do in the near future, although there are many good sites that do that now on the Internet. In the meantime, this is an example of JavaScript within HTML programming. Though this is a "hypothetical sample problem", it is very real. We have NOT changed the names of people or places to protect anyone! We have tried to include as many steps as possible to demonstrate how certain things happen to allow a program to calculate and display correctly. The source code is documented to show what every command does. You may take it and use it as you wish. We do ask that you keep credits in place. We hope that it will be instructional for you. It is our contention that programming (in any language) is a well blended mixture of logic, along with common sense, basic math and reasonable communication between the program (an extension of the programmer) and the user. There are ways to arrive at an answer, and there are BEST ways to arrive at an answer. Over the years, the best way, as far as we are concerned, is the way that has the LEAST chance of incorrect or unanticipated user input. This programming example works well SO LONG AS THE USER follows the instructions given here. We have left a few traps that will show up IF the user does not. We did that hoping that you will take the next step and resolve them for YOUR program. Enjoy and learn. (If you have problems with or questions about THIS example page, you may contact us using the contact form and I will help you as quickly as I can).

Purpose 2. Honor a friend of mine, Ken Huskey; a man among men. He was and is a super-athlete (exception: horseshoes); even approaching senior citizen age, he can "out do" most athletes 30 years his junior. (I've never beaten him at racquetball but I did score a point on him once...) He is an opinionated man, a family man with strong family and youth oriented values, a community man, a mountain man, a desert man, a talented man, a hard working type 'A' personality man. In summary, the kind of man you would like to have as a friend or have with you if you needed to survive in the wilderness. (On the other hand, if you want to catch fish on a given day, don't go with him.) He is the best of the best as far as public speakers and communications consultants go, and he is the ideal, model Riverside County, CA, citizen when it comes to "going to the dump" etiquette. Hence, the source of our problem that we need to resolve. He trims every tree and bush in his yard, his neighbors' yards, his friends' yards, and anyone else's yard that will let him. Then he carefully picks up and cuts up the trash into compacted and manageable pieces that will fit into the bed of his stately, gentleman's Chevy pickup truck. He then further compresses the trash and piles on more, neatly and carefully strapping it and covering it to avoid spreading it along the beautiful southern California roadway, enroute to the County of Riverside dump, one of the many not-very-well known area tourist attractions near Palm Springs and Desert Hot Springs. (When this truck is ready to roll, it is a work of art second only to the Mona Lisa.) He then hauls it to the dump, waving at bystanders and tourists cheering along the wayside, and then willingly PAYS the County of Riverside, California, to allow him to dump his own trash! A true good guy if I have ever seen one.

Purpose 3. Give a severe slap on the wrist to the County of Riverside, California, for an absolutely STUPID and IDIOTIC policy concerning the county dumps. This is my own little editorial forum and I will use it as such. (Where did I leave my soapbox? Here it is...) How many "good guys" do you think there are that will haul their own trash to the dump and then pay to dump it? Why do you think the lower desert area of Southern California is littered with old furniture, refrigerators, washing machines, dead (perhaps live as well) Apple computers and all other forms of garbage and trash? How much of a blight is that on the area? How much does it cost to clean it up? If the dump did not have a cost associated with it, would it still be that way? Wake up Riverside County and smell the roses (or trash in this case)!!! All the trash and rubbish along the roadsides and in the desert is testimony that there are not many Ken Huskeys or those like him, in the area! In Riverside County, it COSTS YOU to do the right thing! Put another way, would you rather have the trash in the dump or in the desert? (Put the soapbox away for next time...)

Our far-fetched (but real) sample problem, dedicated to my friend Ken is this. How much trash can you squeeze into a pickup truck and take to the dump? (How many programmers does it take to get it there?... None, it's a hardware problem... Maybe we can change that...) There are several factors involved. Part 1 is calculate the raw volume potential of the truck's carrying capacity in cubic feet and/or cubic inches. Part 2, refine the actual trash volume to a "close to accurate" amount of dump-destined trash and convert the answer to cubic yards, from cubic feet and cubic inches. Part 3, how much will it cost? We will not approach the question of "Are you going to pay it and stand for this?" I will however, squawk about it from time to time in this document.

Formulae (yes, that's plural) used in this problem: L x W x D (in inches) to calculate the potential cubic inches (potential for trash) of the truck bed. Enter the length of the truck bed in feet and inches, or inches alone, or feet alone. You MUST however, include a 0 in the inches field if there are none, just as the default for feet is 0. In fact, ALL fields must have a value in them, even if the value is 0. The default is 96 for inches in length (8 feet). (Why did we do that? This is a POTENTIAL programming problem that if left "unchecked" will cause a problem. Part of the problem could be JavaScript, part pure math. One potential problem is a divide by 0 (zero) which is an illegal operation in any form of math. In JavaScript, that can also be a problem with addition of fields that "have no value (in theory, 0) but are NOT 0, yielding an error that is an infinite add or subtract. We are telling you about it but someone will do it wrong. You need to validate potential problems like this one, in the code.) Enter the width of the truck bed in inches; the default is 60 inches (5 feet). Enter the depth of the truck bed; the default is 20 inches. We then refine this volume to indicate the approximate volume of the trash as opposed to the truck potential. This does take into consideration an approximation of wheel well intrusion, just to show how it is done, but does not go into the same for a toolbox or other similar intrusions, though you could include those approximations (already in cubic inches) in the wheel well intrusions by entering a value in lieu of the default, in place of the default, in addition to the default, or in combination with a value for the wheel wells and other intrusions. (Details further in the text.) We then convert to cubic inches, cubic feet and cubic yards: Since there are 12 inches on each leg of a cubic foot, 12 x 12 x 12 = the number of cubic inches in a cubic foot, 1728. Since there are 3 feet on each leg of a cubic yard, 3 x 3 x 3 = the number of cubic feet in a cubic yard, 27. Since there are 36 inches in each leg of a cubic yard, 36 x 36 x 36 = the number of cubic inches in a cubic yard, 46656. We take a percentage of the potential volume and deduct "air space" from it, hence the term compression. Enter a value from 1 to 100, 1 being the least compressed and most "air space" in the trash. 100 is the most compressed meaning no "air space in the trash". An example of 1 would be uncompressed and uncut thorn bushes. An example of 100 would be a load of soil. (In our programming example, we are NOT concerned with weight but you can easily figure out how to calculate by weight instead of volume. We ARE still concerned with have to pay the stupid dump fee!) The default is a 50% factor of compression, meaning it is cut up and has some "air space" but is fairly well compressed. (Ken often gets about a 99% compression factor out of bushes, trees and shrubbery cuttings. The dump appreciates him!) We deduct the approximate amount of wheel well intrusion space (and other intrusion space if you can approximate it in cubic inches), a default of 1980 cubic inches, using the approximate values of 15 inches x 11 inches x 6 inches x 2 (one on each side), leaving just enough room for a 4 foot by 8 foot sheet of plywood flat in the bed, and then add any "above the bed" amount, held in by boards, a canopy, a tarp, bags or ropes and straps. That is done by a multiplication factor of any amount, but generally less than 2. (Some positive amount must be in this field.) For instance, 1 would be a full truck bed but NO extra amount above the truck bed; 1.1 would be an extra 10% above the bed volume, at the same, already determined, density. 2 would indicate the volume above would be about the same as the volume in the bed; in other words, a multiplication factor of 2. Most numbers are going to be between 1 and 2; however Ken often gets into the 3s and 4s. A factor of 5 gets you an automatic induction into the Dump Haul Of Fame! You could also use this to indicate that the bed is only half full (in case you didn't want anyone to see that you are hauling trash) by changing the default value of 1 to an entered value of .5, to indicate 1/2. Finally, if there is a price per cubic foot for a dump fee (as in Riverside County, California), you can calculate it (though you probably don't want to) by entering that amount in dollars and cents format, without the dollar sign. Then you can gag that you are supposed to pay it! Click on the Calculate button and the problem is solved (at least the programming problem)! (If it were only that easy with the County of Riverside...) If you want to adjust your values and try again, you can simply edit a field and again click on Calculate, or you can click on Reset Values and clear all the values to their default conditions to start over. Is there a Reset Values for the County of Riverside?

Enter truck bed length in feet
and inches (or all inches)
Enter truck bed width in inches
Enter truck bed depth in inches
Enter the percentage of compression - Range = 0 to 100
Enter extra space factor - (multiplication factor for volume)
Enter wheel well intrusion space in approximated cubic inches
                  (Include all other intrusions to be deducted from volume)

Enter dump charge price per cubic yard (xx.xx) - Optional

            Result in cubic inches
            Result in cubic feet
            Result in cubic yards
    $      Total price



Version 1.1.8

Leave us a question or comment on Facebook
Search or Browse Our Site
Free Information Calculators and Converters

International Copyright Violation
Registered® Trademark™ and Copyrightę 1973 - CSG, Computer Support Group, Inc. and CSGNetwork.Com All Rights Reserved

Home | Advertising | Calculators and Converters | Contact Us | Javascript | Sitemap | Glossary | Top Free Apps