javascript - Count hours figures and set a new day for every 7.5 hours -


i have list of training modules, each has value number of hours takes train. example:

training module 1 - 2.5 hours
training module 2 - 1.0 hours
....

i have them set jquery drag-drop, shopping cart users can grab modules want , drop them container.

when item added container, need work out day of training module placed in. each day 7.5 hours.

what need displayed in drop container this:

training module 1 - 2.5 hours - day 1
training module 2 - 1.0 hours - day 1
training module 3 - 4.0 hours - day 1
training module 4 - 1.0 hours - day 2
training module 5 - 4.5 hours - day 2
training module 6 - 3.0 hours - day 3
....

this i've tried:

var $dayfields = $('#sortable2 li').find('#day'); var $sumhrsfields = $('#sortable2 li').find('#sumhrs');  var hrsarray = $("#sortable2 li").find("#hrsspan").map(function () { return $(this).text() }).get();             //add hrs total (var in hrsarray) {     total += hrsarray[i];     if (total / 7.5 <= 1) {         $($dayfields.get(i)).html('1');         $($sumhrsfields.get(i)).html(total);     }     else if (total / 7.5 > 1) {         daytext = total / 7.5;         //if daytext value ends whole number, don't anything. if isn't, round down whole number , add 1         if (daytext % 1 == 0) {          }          else {             daytext = daytext | 0;             daytext += 1;          }         $($dayfields.get(i)).html(daytext);         $($sumhrsfields.get(i)).html(total-(7.5));     } } 

it works first 2 or 3 days day values dont add up.

is there more elegant appoach this? feel i'm overthinking problem.

here somehow sampler approach:

var hrsarray = [1.75, 1, 3.25, 2.5];  var total = 0;  var hoursinday = 7.5;  (var in hrsarray) {    var moduleno = parseint(i) + 1;    total += hrsarray[i];    var days = math.floor(total / hoursinday);    var daytext = days + 1; // need add 1 1-day ahead      $('#display').append('module ' + moduleno + ': ' + hrsarray[i] + ' hours, day ' + daytext);    $('#display').append('<br/>');  }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>  <div id="display"/>


Comments

Popular posts from this blog

Email notification in google apps script -

c++ - Difference between pre and post decrement in recursive function argument -

javascript - IE11 incompatibility with jQuery's 'readonly'? -