Simplified Bin Packing using JavaScript This code determines the maximum number of boxes (one size) that can fit into the back of a truck, checking all possible orientations to ensure maximum Bin Packing excitement.  This is (hopefully) the final version of this code. Please share any modifications that you would make to this code below.

&lt;!DOCTYPE html&gt;
&lt;html&gt;
&lt;script&gt;

// This program determines the maximum number of boxes that can fit into the back of a truck

// Declaring box size in centimetres, and converting it into metres
var boxHeight = prompt("What is the height of your box in centimetres?") / 100;
var boxWidth = prompt("What is the width of your box in centimetres?") / 100;
var boxLength = prompt("What is the length of your box in centimetres?") / 100;

// Declaring truck size in metres
var truckHeight = prompt("What is the height of your truck in metres?");
var truckWidth = prompt("What is the width of your truck in metres?");
var truckLength = prompt("What is the length of your truck in metres?");

// Declaring variables used in equation
var heightA = boxHeight &gt; 0 ? ((truckHeight / boxHeight) | 0) : 0;
var widthA = boxWidth &gt; 0 ? ((truckWidth / boxWidth) | 0) : 0;
var lengthA = boxLength &gt; 0 ? ((truckLength / boxLength) | 0) : 0;

var heightB = boxHeight &gt; 0 ? ((truckHeight / boxHeight) | 0) : 0;
var widthB = boxWidth &gt; 0 ? ((truckLength / boxWidth) | 0) : 0;
var lengthB = boxLength &gt; 0 ? ((truckWidth / boxLength) | 0) : 0;

var heightC = boxHeight &gt; 0 ? ((truckWidth / boxHeight) | 0) : 0;
var widthC = boxWidth &gt; 0 ? ((truckHeight / boxWidth) | 0) : 0;
var lengthC = boxLength &gt; 0 ? ((truckLength / boxLength) | 0) : 0;

var heightD = boxHeight &gt; 0 ? ((truckWidth / boxHeight) | 0) : 0;
var widthD = boxWidth &gt; 0 ? ((truckLength / boxWidth) | 0) : 0;
var lengthD = boxLength &gt; 0 ? ((truckHeight / boxLength) | 0) : 0;

var heightE = boxHeight &gt; 0 ? ((truckLength / boxHeight) | 0) : 0;
var widthE = boxWidth &gt; 0 ? ((truckWidth / boxWidth) | 0) : 0;
var lengthE = boxLength &gt; 0 ? ((truckHeight / boxLength) | 0) : 0;

var heightF = boxHeight &gt; 0 ? ((truckLength / boxHeight) | 0) : 0;
var widthF = boxWidth &gt; 0 ? ((truckHeight / boxWidth) | 0) : 0;
var lengthF = boxLength &gt; 0 ? ((truckWidth / boxLength) | 0) : 0;

var multiplesA = heightA * widthA * lengthA;
var multiplesB = heightB * widthB * lengthB;
var multiplesC = heightC * widthC * lengthC;
var multiplesD = heightD * widthD * lengthD;
var multiplesE = heightE * widthE * lengthE;
var multiplesF = heightF * widthF * lengthF;

var arrayA = [multiplesB, multiplesC, multiplesD, multiplesE, multiplesF];  
var arrayB = [multiplesA, multiplesC, multiplesD, multiplesE, multiplesF];
var arrayC = [multiplesB, multiplesA, multiplesD, multiplesE, multiplesF];
var arrayD = [multiplesB, multiplesC, multiplesA, multiplesE, multiplesF];
var arrayE = [multiplesB, multiplesC, multiplesD, multiplesA, multiplesF];
var arrayF = [multiplesB, multiplesC, multiplesD, multiplesE, multiplesA];


// Calculating the most efficient orientation of the boxes
var boxCount;

if (multiplesA &gt; arrayA)
{
boxCount = multiplesA;
}

else if (multiplesB &gt; arrayB)
{
boxCount = multiplesB;
}

else if (multiplesC &gt; arrayC)
{
boxCount = multiplesC;
}

else if (multiplesD &gt; arrayD)
{
boxCount = multiplesD;
}

else if (multiplesE &gt; arrayE)
{
boxCount = multiplesE;
}

else
{
boxCount = multiplesF;
}

// Output answer
alert("You can fit up to " + boxCount + (1 == boxCount ? " box" : " boxes") + " into the truck");

&lt;/script&gt;
&lt;/html&gt;
I think a big first improvement for you will be to start DRYing out your code. You should create a function which returns the ratio of two sides -- there is much too much repetition in your code. Something like:

function get_ratio(x, y) {
    if (y === 0) {
        return 0
    }
    return x/y | 0
}