• Resolved fibbu

    (@fibbu)


    Hello;
    I added a [Text Area]- [fieldname37] field, users enter random numbers in the form of 1,6,9,8.

    I also want to calculate the arithmetic average of the digits entered with the code below.

    I think I’m making a mistake somewhere in the code, any suggestions?

      (function() {
        var inputValues = jQuery('[name="fieldname37"]').val();
        var numbers = inputValues.split(',').map(parseFloat);
        var sum = numbers.reduce((total, num) => total + num, 0);
        var count = numbers.length;
        var arithmetic= sum / count;
    
        jQuery('#calculation-kriter3').html(arithmetic);
        jQuery('.arithmetic-aciklama').html('Arithmetic : ');
        jQuery('.arithmetic-sonuc').html(arithmetic);
        
        return [arithmetic];
      })();
Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Author codepeople

    (@codepeople)

    Hello @fibbu

    Please, edit the lines of code:

    var inputValues = jQuery('[name="fieldname37"]').val();

    As:

    var inputValues = fieldname37;

    And

    return [arithmetic];

    As:

    return arithmetic;

    Note you have no control over the values entered by users. They can use spaces between commas and numbers, currency symbols, or even changes of lines because you say to use a textarea control. So, you must preprocess the values entered by users before splitting them.

    Best regards.

    Thread Starter fibbu

    (@fibbu)

    So, do you have a better solution? Something we will do for this calculation tool without using textarea?

    Sample

    This is the site I took as an example.
    Thanks.

    Thread Starter fibbu

    (@fibbu)

    I have written rules in the form of counting the numbers entered outside of the digits and counting the number of elements entered other than the numbers in the same way. Thanks.

    Plugin Author codepeople

    (@codepeople)

    Hello @fibbu

    Do you have applied the recommended modifications? Is your equation working fine now?

    Best regards.

    Thread Starter fibbu

    (@fibbu)

    Yes, yes, I ran it, I added letter character rules, it’s working fine now, thank you for your attention.

    Plugin Author codepeople

    (@codepeople)

    Excellent !!!

    Thanks.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Arithmetic Code Error’ is closed to new replies.