title: I need help in assigning trailer compartments to animals
body: <p>We have 4 compartments in a trailer:</p>
  <p><code>var Compartments = [240, 240, 200, 180];</code></p>
  <p>Now, We have to assign compartments to the animals for e.g.: Bulls are high in quantity so they have required 2 compartments (that I already have calculated by %)</p>
  <pre><code>var TotalLoadWeight = parseInt(bullWeight) + parseInt(cowWeight) + parseInt(calfWeight);
  var bullperc = parseInt(bullWeight / TotalLoadWeight * 100);
  var cowperc = parseInt(calfWeight / TotalLoadWeight * 100);
  var calfperc = parseInt(calfWeight / TotalLoadWeight * 100);
  
  var bullCompartment = Math.round(bullperc / 100 * 4); // 2
  var cowCompartment = Math.round(cowperc / 100 * 4); // 1
  var calfCompartment = Math.round(calfperc / 100 * 4); // 1
  
  var compAllocate = [bullCompartment, cowCompartment, calfCompartment];
  </code></pre>
  <p>Problem Statement:
  Answer should be - Bull will take 240 &amp; 240; Cow will take 200; Calf will take 180, but I am not getting this answer.
  More details: Assign first two compartments to Bull (because Bull count is 2) &amp; those compartments will not repeat for next two.</p>
  <pre><code>for(var x = 0; x &lt; compAllocate.length; x++{
      for(var i = 0; i &lt; compAllocated[x]; i++){
          console.log(&quot;Compartments&quot; + Compartments[x]); // Not getting proper answer.
      }
  }
  </code></pre>
  <p>These loops are repeating: compartment 1 &amp; 2 for bull, again compartment 1 for cow</p>