Skip to content

Instantly share code, notes, and snippets.

@mileszs
Forked from unixmonkey/liftcalc.html
Created March 4, 2010 18:17
Show Gist options
  • Save mileszs/321974 to your computer and use it in GitHub Desktop.
Save mileszs/321974 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html lang='en'>
<head>
<title>LiftCalc</title>
<meta http-equiv='Content-type' content='text/html;charset=UTF-8'>
<meta name='viewport' content='width=device-width'>
<meta name='viewport' content='initial-scale=1.6'>
<script type='text/javascript' src='http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js'></script>
<script type='text/javascript'>
var LiftCalc = function(){
var maxweight = 0;
return {
calculate: function(checkweight, reps){
maxweight = ( checkweight / ( 1.0278 - ( 0.0278 * reps ) ) );
return this.round_down(maxweight);
},
max_percent: function(percentage){
var weight = (maxweight * percentage) / 100;
return this.round_down(weight);
},
round_down: function(weight){
var rounded = Math.floor((weight / 5)) * 5;
return rounded;
},
result: function(){
var output = "Your calculated max (rounded down to the nearest 5 lbs) is:\n";
output += "--------\n";
output += "| "+ this.round_down(maxweight) +" lbs |\n";
output += "--------\n";
output += "Try and do this:\n";
output += "15 reps at 45% ("+ this.max_percent(45) +" lbs)\n";
output += " 7 reps at 60% ("+ this.max_percent(60) +" lbs)\n";
output += " 5 reps at 75% ("+ this.max_percent(75) +" lbs)\n";
output += " 3 reps at 80% ("+ this.max_percent(85) +" lbs)\n";
output += " 2 reps of 90% ("+ this.max_percent(90) +" lbs)\n";
return output;
},
result_as_html: function(){
return this.result().replace(/\n/g, '<br>');
}
}
}
$(document).ready(function(){
$('#formy').submit(function(){
// get form stuffs
var checkweight = $('input[name=checkweight]').val();
var reps = $('input[name=reps]').val();
// see what the oracle says
var lc = new LiftCalc
lc.calculate(checkweight, reps);
// $('#resultset').empty().replaceWith(lc.result_as_html());
alert(lc.result());
return false; // prevents actual form submit
});
});
</script>
<style type='text/css'>
body { width: 190px; color: #FFFFFF; background-color: #CB14E3; }
fieldset { width: 174px; background-color: #6818F2; }
header { background-color: #CB14E3; }
header p { width: 180px; }
p#submitter { margin: 0 auto; text-align: center; }
</style>
</head>
<body>
<header>
<p>
This regimen calculator based on the Justin Cunningham's blog post,
<em>"<a href='http://littlebitofcode.com/2010/03/01/get-in-shape'>Get In Shape</a>"</em>
</p>
</header>
<section>
<form id='formy'>
<fieldset>
<p>
<label for='checkweight'>
Enter a weight you believe you can lift between 2 and 10 times, but no more.
</label>
<br>
<input id='checkweight' type='number' name='checkweight' min='0' step='5' placeholder='checkweight (in pounds)' autofocus='autofocus'>
</p>
<p>
<label for='reps'>
How many were you able to do?
</label>
<br>
<input id='reps' type='number' name='reps' min='0' max='10' placeholder='repetitions'>
</p>
<p id='submitter'>
<input type='submit' name='submit' value='Show Results'>
</p>
</fieldset>
</form>
</section>
<div id='resultset'></div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment