How can I average numbers from the database?
Could you show us screenshots with that code in the success event and it's response?
Catch up wih the Appery.io community on our forum. Here you'll find information on the lastest questions and issues Appery.io developers are discussing.
https://forum.appery.io/
Could you show us screenshots with that code in the success event and it's response?
Here is the code: https://d2r1vs3d9006ap.cloudfront.net...
Here is the result:
https://d2r1vs3d9006ap.cloudfront.net...
Please use a JS below there to check the service response to be sure there are correct data:
prealert(JSON.stringify(data));/pre
Please here an example how to calculate average sum: http://stackoverflow.com/questions/10...
values of your array "grades" might be not a number, so just add a parseInt or parseFloat methods here
What values does you variable "grades" have? it seems it has wrong values... Could you send us it's value?
Grades contains the values from the LSV 'average weight' that are mapped in this same service. The values are numbers and if you look at this screenshot, the pink is what the console logs as in that variable. https://d2r1vs3d9006ap.cloudfront.net...
Do you have an update here?
There are empty values, which are not numbers. To prevent NaN error, please check these values before use them in the average value calculation.
Please change JS code:
pretotal += parseFloat(grades);/pre
to:
pretotal += parseFloat(grades || 0);/pre
Switching out those lines of code didn't change anything. I still get the NaN error.
Please send us a result of prealert(JSON.stringify(grades));/pre (screenshot).