• Resolved chadtesting

    (@chadtesting)


    Sorry if this question has been asked before, but I’m having trouble finding the proper operators to calculate an average.

    I have 4 fields

    fieldname1
    fieldname2
    fieldname3
    fieldname4

    The user does not have to fill out all the fields, but of the ones filled out, I need to calculate an average. I can’t just use 1+2+3+4/4 – I have to set it so that it calculated the average of only the fields filled out.

    Can someone help?

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author codepeople

    (@codepeople)

    Hello,

    The process is very simple, you should check if the field has assigned a value to increase a counter that will be used to calculate the average, similar to the following code:

    (function(){
    var values = [fieldname1,fieldname2,fieldname3, fieldname4],
        total = 0,
        counter = 0;
    
    for(var i in values)
    {
    if(values[i]) counter++;
    total += values[i];
    }
    
    return (counter)?total/counter:0;
    })()

    and that’s all.
    Best regards.

    Thread Starter chadtesting

    (@chadtesting)

    That worked brilliantly.

    The problem I’m finding (and I think I’ll continue to find) as I work through my project, is that while I am smart enough to ask good questions and figure out how to apply your solutions, I don’t have the ability to code this project outside of the nice little walled garden you’ve made for us.

    By the time I’m done, I want to have multiple levels of conditional show/hide logic based on calculating half a dozen data points, some which are numeric ranges, and some which are true/false. I just don’t see me being able to do this properly, even if I buy the retail version, without a solid foundation in javascript, Jquery, and CSS. Please tell me I’m wrong ??

    Plugin Author codepeople

    (@codepeople)

    Hello @chadtesting,

    The skills required to use our plugin depends of the project’s complexity. The plugin is very versatile and give the user the possibility to implement all type of projects. If you want to implement complex formulas for checking numeric ranges, show/hide fields based on complex conditions, then, you might need some additional skills.

    Best regards.

    Thread Starter chadtesting

    (@chadtesting)

    So my next question is, do you charge an hourly rate to help round out existing projects given specifications?

    Because I feel like I can take this so far with your plugin, but then I will need some dedicated hours of your time to finish the project.

    The upside to this is that I will have a good understanding of the plugin to make changes within it once you are finished, and I can work with you in the future.

    Plugin Author codepeople

    (@codepeople)

    Hello @chadtesting,

    Yes of course, please, send me the project’s specifications through my personal website:

    https://cff.dwbooster.com/customization

    Best regards.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Calculating an average’ is closed to new replies.