Skip to content

Instantly share code, notes, and snippets.

@cronco
Created March 1, 2017 23:53
Show Gist options
  • Save cronco/e1d3c566edf5be814a89ce6640517c4b to your computer and use it in GitHub Desktop.
Save cronco/e1d3c566edf5be814a89ce6640517c4b to your computer and use it in GitHub Desktop.
JS Bin // source http://jsbin.com/cixetomama
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
<script src="https://code.jquery.com/jquery-3.1.0.js"></script>
<style id="jsbin-css">
label {
display:block;
margin: 20px;
}
label input {
float: right;
}
</style>
</head>
<body>
<label> Months<input type="number" id="months" value="1"/></label>
<label> Boxes<input type="number" id="boxes" value="2"/></label>
<button id="calculate">Calculate</button>
<label> Per month<input type="number" disabled="true" id="per-month"/></label>
<label> Total<input type="number" disabled="true" id="total"/></label>
<script id="jsbin-javascript">
var months= [], i, j;
months[0] = [];
for (i =1; i<=12; i++) {
months[i] = [0];
for (j = 1; j<=50; j++) {
switch(i){
case 1:
case 2:
if (j < 5) {
months[i][j] = 5;
}
if (j >= 5 && j < 10) {
months[i][j] = 4.50;
}
if (j >= 10 && j < 20) {
months[i][j] = 4.25;
}
if (j >= 20 && j < 50) {
months[i][j] = 4;
}
if (j == 50) {
months[i][j] = 3.5;
}
break;
case 3:
case 4:
case 5:
if (j < 5) {
months[i][j] = 4.5;
}
if (j >= 5 && j < 10) {
months[i][j] = 4.05;
}
if (j >= 10 && j < 20) {
months[i][j] = 3.83;
}
if (j >= 20 && j < 50) {
months[i][j] = 3.6;
}
if (j == 50) {
months[i][j] = 3.15;
}
break;
case 6:
case 7:
case 8:
if (j < 5) {
months[i][j] = 4.25;
}
if (j >= 5 && j < 10) {
months[i][j] = 3.83;
}
if (j >= 10 && j < 20) {
months[i][j] = 3.61;
}
if (j >= 20 && j < 50) {
months[i][j] = 3.4;
}
if (j == 50) {
months[i][j] = 2.98;
}
break;
case 9:
case 10:
case 11:
if (j < 5) {
months[i][j] = 4;
}
if (j >= 5 && j < 10) {
months[i][j] = 3.6;
}
if (j >= 10 && j < 20) {
months[i][j] = 3.4;
}
if (j >= 20 && j < 50) {
months[i][j] = 3.2;
}
if (j == 50) {
months[i][j] = 2.8;
}
break;
case 12:
if (j < 5) {
months[i][j] = 3.5;
}
if (j >= 5 && j < 10) {
months[i][j] = 3.15;
}
if (j >= 10 && j < 20) {
months[i][j] = 2.98;
}
if (j >= 20 && j < 50) {
months[i][j] = 2.8;
}
if (j == 50) {
months[i][j] = 2.45;
}
break;
}
}
}
$('#calculate').click(function(e) {
var monthsVal = parseInt($('#months').val(), 10);
var boxesVal = parseInt($('#boxes').val(), 10);
if (monthsVal && boxesVal) {
$('#per-month').val(months[monthsVal][boxesVal]);
$('#total').val(months[monthsVal][boxesVal] * monthsVal * boxesVal);
}
});
</script>
<script id="jsbin-source-css" type="text/css">label {
display:block;
margin: 20px;
}
label input {
float: right;
}</script>
<script id="jsbin-source-javascript" type="text/javascript">var months= [], i, j;
months[0] = [];
for (i =1; i<=12; i++) {
months[i] = [0];
for (j = 1; j<=50; j++) {
switch(i){
case 1:
case 2:
if (j < 5) {
months[i][j] = 5;
}
if (j >= 5 && j < 10) {
months[i][j] = 4.50;
}
if (j >= 10 && j < 20) {
months[i][j] = 4.25;
}
if (j >= 20 && j < 50) {
months[i][j] = 4;
}
if (j == 50) {
months[i][j] = 3.5;
}
break;
case 3:
case 4:
case 5:
if (j < 5) {
months[i][j] = 4.5;
}
if (j >= 5 && j < 10) {
months[i][j] = 4.05;
}
if (j >= 10 && j < 20) {
months[i][j] = 3.83;
}
if (j >= 20 && j < 50) {
months[i][j] = 3.6;
}
if (j == 50) {
months[i][j] = 3.15;
}
break;
case 6:
case 7:
case 8:
if (j < 5) {
months[i][j] = 4.25;
}
if (j >= 5 && j < 10) {
months[i][j] = 3.83;
}
if (j >= 10 && j < 20) {
months[i][j] = 3.61;
}
if (j >= 20 && j < 50) {
months[i][j] = 3.4;
}
if (j == 50) {
months[i][j] = 2.98;
}
break;
case 9:
case 10:
case 11:
if (j < 5) {
months[i][j] = 4;
}
if (j >= 5 && j < 10) {
months[i][j] = 3.6;
}
if (j >= 10 && j < 20) {
months[i][j] = 3.4;
}
if (j >= 20 && j < 50) {
months[i][j] = 3.2;
}
if (j == 50) {
months[i][j] = 2.8;
}
break;
case 12:
if (j < 5) {
months[i][j] = 3.5;
}
if (j >= 5 && j < 10) {
months[i][j] = 3.15;
}
if (j >= 10 && j < 20) {
months[i][j] = 2.98;
}
if (j >= 20 && j < 50) {
months[i][j] = 2.8;
}
if (j == 50) {
months[i][j] = 2.45;
}
break;
}
}
}
$('#calculate').click(function(e) {
var monthsVal = parseInt($('#months').val(), 10);
var boxesVal = parseInt($('#boxes').val(), 10);
if (monthsVal && boxesVal) {
$('#per-month').val(months[monthsVal][boxesVal]);
$('#total').val(months[monthsVal][boxesVal] * monthsVal * boxesVal);
}
}); </script></body>
</html>
label {
display:block;
margin: 20px;
}
label input {
float: right;
}
var months= [], i, j;
months[0] = [];
for (i =1; i<=12; i++) {
months[i] = [0];
for (j = 1; j<=50; j++) {
switch(i){
case 1:
case 2:
if (j < 5) {
months[i][j] = 5;
}
if (j >= 5 && j < 10) {
months[i][j] = 4.50;
}
if (j >= 10 && j < 20) {
months[i][j] = 4.25;
}
if (j >= 20 && j < 50) {
months[i][j] = 4;
}
if (j == 50) {
months[i][j] = 3.5;
}
break;
case 3:
case 4:
case 5:
if (j < 5) {
months[i][j] = 4.5;
}
if (j >= 5 && j < 10) {
months[i][j] = 4.05;
}
if (j >= 10 && j < 20) {
months[i][j] = 3.83;
}
if (j >= 20 && j < 50) {
months[i][j] = 3.6;
}
if (j == 50) {
months[i][j] = 3.15;
}
break;
case 6:
case 7:
case 8:
if (j < 5) {
months[i][j] = 4.25;
}
if (j >= 5 && j < 10) {
months[i][j] = 3.83;
}
if (j >= 10 && j < 20) {
months[i][j] = 3.61;
}
if (j >= 20 && j < 50) {
months[i][j] = 3.4;
}
if (j == 50) {
months[i][j] = 2.98;
}
break;
case 9:
case 10:
case 11:
if (j < 5) {
months[i][j] = 4;
}
if (j >= 5 && j < 10) {
months[i][j] = 3.6;
}
if (j >= 10 && j < 20) {
months[i][j] = 3.4;
}
if (j >= 20 && j < 50) {
months[i][j] = 3.2;
}
if (j == 50) {
months[i][j] = 2.8;
}
break;
case 12:
if (j < 5) {
months[i][j] = 3.5;
}
if (j >= 5 && j < 10) {
months[i][j] = 3.15;
}
if (j >= 10 && j < 20) {
months[i][j] = 2.98;
}
if (j >= 20 && j < 50) {
months[i][j] = 2.8;
}
if (j == 50) {
months[i][j] = 2.45;
}
break;
}
}
}
$('#calculate').click(function(e) {
var monthsVal = parseInt($('#months').val(), 10);
var boxesVal = parseInt($('#boxes').val(), 10);
if (monthsVal && boxesVal) {
$('#per-month').val(months[monthsVal][boxesVal]);
$('#total').val(months[monthsVal][boxesVal] * monthsVal * boxesVal);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment