• Resolved klingbeil

    (@klingbeil)


    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 1 year, 4 months ago by klingbeil.
Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author codepeople

    (@codepeople)

    Hello @klingbeil

    The code can be implemented as follows:

    
    (function(){
    var v = [fieldname29|r, fieldname30|r, fieldname38|r, fieldname39|r].filter(n => n != '');
    return SUM(v)/v.length;
    })()

    Best regards.

    Thread Starter klingbeil

    (@klingbeil)

    As a result of how I add this part, I print an output.

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

    it didn’t happen this way.

    (function(){
    var yaziliortalama = [fieldname29|r, fieldname30|r, fieldname38|r, fieldname39|r].filter(n => n != '');
      jQuery('#calculation-yaziliortalama').html(yaziliortalama);
      jQuery('.kriter1-yaziliortalama').html('Yaz?l? S?nav Ortalamas? :');
      jQuery('.kriter1-yaziliortalama').html(yaziliortalama);
    
    return SUM(yaziliortalama)/yaziliortalama.length;
    })()

    Thank you for your support.

    Plugin Author codepeople

    (@codepeople)

    Hello @klingbeil

    You must assign the mathematical result to a variable, like:

    var result = SUM(yaziliortalama)/yaziliortalama.length;

    And then use this variables, in code like:

    jQuery('#calculation-yaziliortalama').html(result);

    To finally return it:

    return result;

    Please, note we don’t implement the users’ projects via the WordPress forum. If you need someone that implement your project or equations, you can contact us via the plugin website:

    https://cff.dwbooster.com/contact-us

    Best regards.

    Thread Starter klingbeil

    (@klingbeil)

    Thank you for your support.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Average Calculator’ is closed to new replies.