Average Grade Calculator Using JQuery -


i'm working project calculates average grade. code works gives me wrong answer.

my code allows user enter of his/her 'grade' , 'units'.

so example:

                  grade   |   number of units     subject 1:      2.00              3    subject 2:      1.50              5    subject 3:      1.75              2 

the calculation be: average=((2.00*3)+(1.50*3)+(1.75*2) / total of units)

average = (6+4.5+3.5) / 10  average = 1.7 

the problem in code sums grades divides sum of units.

here jsfiddle link: http://jsfiddle.net/n4nkmxtx/

take jsfiddle: http://jsfiddle.net/n4nkmxtx/2/

i have changed calculation function:

$("#addall").click(function() {     var grade = 0;     var units = 0;      var grades = $(".grade");     var units = $(".units");     var total = 0; // counts total sum of multiplications     var unitstotal = 0; // counts total sum of units      (var = 0; < grades.length; i++)     {         total += number($(grades).eq(i).val()) * number($(units).eq(i).val());         unitstotal += number($(units).eq(i).val());     }      var average = total / unitstotal;      $("#para").text("average : " + average); }); 

we save array of grade inputs , array of units arrays.
assuming have equal length, iterate through them , calculate sum of totals , total count of units.

jquery.eq() stands getting n-th item jquery object.


Comments

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

jdbc - Not able to establish database connection in eclipse -

Kivy: Swiping (Carousel & ScreenManager) -