• Resolved shabean

    (@shabean)


    Hello.

    Great plugin. I would like to create a relatively simple travel insurance quote calculator.

    fieldname5 is Number of days
    fieldname9 is Number of insured

    The quote should work out the following:

    If the number of travel days is between 1 and 7 then the cost is $270 * the number of insured.

    If the number of travel days is between 8 and 15 then the cost is $570 * the number of insured.

    If the number of travel days is between 16 and 31 then the cost is $570 * the number of insured.

    and so on..

    I am using this formula but it is not returning the correct results.

    (function(){

    if(fieldname5 <= 7) return 270*fieldname9;
    if(fieldname5 >=8 <=15) return 570*fieldname9;
    if(fieldname5 >=16 <=31) return 940*fieldname9;

    })();

    Where have I gone wrong?

    Thanks in advance.

    https://wordpress.org/plugins/calculated-fields-form/

Viewing 1 replies (of 1 total)
  • Plugin Author codepeople

    (@codepeople)

    Hi,

    The format of conditional statements are wrong.

    The “AND” operator in javascript is represented by the symbol “&&”, and the intervals require the combination of two comparisons:

    if(b<=a && a<=c)

    So, the correct format of the equation would be:

    (function(){
    if(fieldname5<=7) return 270*fieldname9;
    if( 8<=fieldname5 && fieldname5<=15) return 570*fieldname9;
    if( 16<=fieldname5 && fieldname5<=31) return 940*fieldname9;
    })()

    Best regards.

Viewing 1 replies (of 1 total)
  • The topic ‘Conditional values for insurance quote’ is closed to new replies.