Nalini
Posts: 0
Joined: Tue Jan 14, 2014 2:49 pm

Calculate average from values in database, then show output in UI labels

Hello, almost everything is working but my script is not calculating correctly for 2 averages for 2 variables. Can u spot any errors?

var courtesyVal = 0,
overallVal = 0,
i;

if(data.length) {

Code: Select all

 for (i = 0; i < data.length; i++) { 

     courtesyVal += data[i].grade_courtesy; 
     overallVal += data[i].grade_overall; 

 } 

 courtesyVal = courtesyVal / data.length; 
 overallVal = overallVal / data.length; 

}

Appery("courtesy_grade").text(courtesyVal);
Appery("overall_grade").text(overallVal);

Nalini
Posts: 0
Joined: Tue Jan 14, 2014 2:49 pm

Calculate average from values in database, then show output in UI labels

Hello, the script is okay, error was the format of the data in appery database. Thanks for all of your help.

Alena Prykhodko
Posts: 0
Joined: Tue Apr 09, 2013 7:36 am

Calculate average from values in database, then show output in UI labels

Thanks for update. Glad it's working.

Return to “Issues”