Skip to content

Instantly share code, notes, and snippets.

@HSchmale16
Last active August 29, 2015 14:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save HSchmale16/29d69b0855f13cb1b8fe to your computer and use it in GitHub Desktop.
Save HSchmale16/29d69b0855f13cb1b8fe to your computer and use it in GitHub Desktop.
Cost of Penny
<html>
<head>
<script type="text/javascript">
</head>var GRAV = 9.81;
var JOULE_KCAL = 0.000239005736;
function fh(h) {return .97 * h;}
function fm1(m) {return .95 * m;}
function fm2(m) {return fm1(m) + .0031;}
function makeTable(h){
var t = '<table><tr><td>Calories</td><td>' + h.calor.toFixed(6) +
'kcal</td></tr><tr><td>Cost of Wages</td><td>$' + h.wagecost.toFixed(6) +
'</td></tr><tr><td>Cost of Calories</td><td>$' + h.calorcost.toFixed(6) +
'</td></tr><tr><td>Total Cost</td><td>$' + h.totcost.toFixed(6) +
'</td></tr></table>';
if(h.totcost > 0.01){
t += '<p>A penny is more trouble than it\'s worth.</p>';
}else{
t += '<p>A penny is worth it.</p>';
}
return t;
}
function calc(){
var height = document.forms.f.height.value / 100.0 * 0.98;
var mass = document.forms.f.mass.value;
var wage = document.forms.f.wage.value / 3600.0;
var dt = document.forms.f.dt.value;
var calcost = document.forms.f.calcost.value;
var wagecost= (dt * wage); // wage cost
var dnJoule = fm1(mass) * fh(height) * GRAV; // joules used going down
var upJoule = fm2(mass) * fh(height) * GRAV;
var calor = (dnJoule + upJoule) * JOULE_KCAL;
var calorcost = calcost * calor;
var totcost = calorcost + wagecost;
document.getElementById('out').innerHTML =
makeTable({calor, wagecost, calorcost, totcost});
}
</script>
<body>
<form name="f" action="javascript:calc()">
Height (cm):<br/>
<input type="text" value="2" name="height"><br/>
Mass (kg):<br/>
<input type="text" value="70" name="mass"><br/>
Hourly Wage (USD/hr):<br/>
<input type="text" name="wage" value="7.25"><br/>
Time to pick it up (Seconds):<br/>
<input type="text" name="dt" value="2"><br/>
Cost Per Caloroie(USD/food cal):<br/>
<input type="text" name="calcost" value="0.005"><br/>
<input type="submit" value="Calculate">
</form>
<div id="out"></div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment