»
EnglishFrenchVietnamese

Print - Gasoline Usage Calculator - JavaScriptBank.com

Full version: jsB@nk » Calculation » Gasoline Usage Calculator
URL: https://www.javascriptbank.com/gasoline-usage-calculator.html

Gasoline Usage Calculator © JavaScriptBank.comTrying to keep track of gasoline expenses? This JavaScript calculates how many miles you are getting per gallon - per day and per year. It also calculates the amount spent per year and how much CO2 your car is producing.

Full version: jsB@nk » Calculation » Gasoline Usage Calculator
URL: https://www.javascriptbank.com/gasoline-usage-calculator.html



JavaScript
<script type="text/javascript"><!-- Begin/* This script and many more are available free online atCreated by: Matthew Ogden :: http://www.home.earthlink.net/~ogden1972/ */function d(){  var a = document.form1.miles.value;  var b = document.form1.gas.value;  var c = document.form1.days.value;  var cost = document.form1.cost.value;  mpg=a/b;  gpd=b/c;  mpg= Math.round(mpg*10)/10;  gpy=gpd*365;  co=gpy*19.36;  cpy=gpy*cost;  gpd= Math.round(gpd*1000)/1000;  gpy= Math.round(gpy*10)/10;  cpy= Math.round(cpy*100)/100;  co= Math.round(co);  document.form1.results.value="Your car is getting "+mpg+" miles per gallon. On the average you use "+gpd+" gallons per day. At that rate of consumption you will burn "+gpy+" gallons per year at a cost of $"+cpy+" per year. In addition, that produces "+co+" pounds of CO2 in one year.";}// End --></script><!--    This script downloaded from www.JavaScriptBank.com    Come to view and download over 2000+ free javascript at www.JavaScriptBank.com-->


HTML
<form name="form1"><strong>Miles Traveled:</strong>  <input type="text" size="8" name="miles">   <strong>Gallons of Gas:</strong>  <input type="text" size="6" name="gas"><br><br><strong>Cost of Gas: $</strong><input type="text" size="4" name="cost">  <strong>Days Between Fill-Ups:</strong>  <input type="text" size="6" name="days"><br><br><input type="button" value="Calculate" onclick="d()"> <input type="Reset" value="Clear"><br><br><strong>Results</strong><br><textarea name="results" rows="5" cols="55" wrap style="border-width:0;overflow:hidden"onfocus="this.blur()"></textarea></form><!--    This script downloaded from www.JavaScriptBank.com    Come to view and download over 2000+ free javascript at www.JavaScriptBank.com-->