Average Calculator | WordPress.org

[ad_1]

Hello
Now I want to calculate the average of 4 numbers, but if one of the 4 number values is not entered as a null value, I want it to calculate the average by dividing it by the remaining 3 numbers. So I’m trying to calculate the average. I made a coding at the bottom, but I couldn’t run it, where is the error?
Sample ; 1,2,3,4 average = 2,5
1,2,4 = average = 2,66 (3. field example not entered)
Thanks

(function(){
  var yaziliortalama;

  var kutucuk1 = fieldname29;
  var kutucuk2 = fieldname30;
  var kutucuk3 = fieldname38;
  var kutucuk4 = fieldname39;

  var toplam = 0;
  var sayac = 0;

  if (!isNaN(kutucuk1)) {
    toplam += kutucuk1;
    sayac++;
  }

  if (!isNaN(kutucuk2)) {
    toplam += kutucuk2;
    sayac++;
  }

  if (!isNaN(kutucuk3)) {
    toplam += kutucuk3;
    sayac++;
  }

  if (!isNaN(kutucuk4)) {
    toplam += kutucuk4;
    sayac++;
  }

  yaziliortalama = toplam / sayac;

  jQuery('#calculation-yaziliortalama').html(yaziliortalama);
  jQuery('.kriter1-yaziliortalama').html('Yazılı Sınav Ortalaması :');
  jQuery('.kriter1-yaziliortalama').html(yaziliortalama);

  return [yaziliortalama];
})();
  • This topic was modified 28 minutes ago by klingbeil.

 

This site will teach you how to build a WordPress website for beginners. We will cover everything from installing WordPress to adding pages, posts, and images to your site. You will learn how to customize your site with themes and plugins, as well as how to market your site online.

Buy WordPress Transfer