• Resolved aesch777

    (@aesch777)


    Hi I am trying to create a calculation amount based on the following answers on the form:
    -their annual income (fieldname 2)
    -their monetary assets (fieldname 3)
    -number of people in their household (fieldname16)
    -status (Single or Married) (Fieldname15)
    -Financing Plan (Yes or No) (fieldname20)

    This is what I got so far, any suggestions, corrections, or help would be greatly appreciated!

    a)
    Condition:

    If one person household (fieldname16), with NO finance plan (fieldname20), annual income is less than $15,000 (fieldname 2) and monetary assets is less than $3000 (fieldname 3) = value is 7000

    Code:
    if(fieldname16 < 2 && fieldname20 == No && fieldname2 < 15000 && fieldname3 < 3000) return 7000;

    b)
    Condition:

    If one person household, with a finance plan, annual income is less than $15,000 and monetary assets is less than $3000 assets = value is 8400

    Code:
    if(fieldname16 < 2 && fieldname20 == Yes && fieldname2 < 15000 && fieldname3 < 3000) return 8400;

    c)
    Condition:

    If one person household, with NO finance plan, annual income is between $15,000 and $35000, monetary assets is less than $3000 assets = value is 9000

    Code:
    if(fieldname16 < 2 && fieldname20 == No && fieldname2 >= 15000 && fieldname2 <=35000 && fieldname3 < 6000) return 9000;

    d)
    Condition:
    If one person household, with a finance plan, annual income is between $15,000 and $35000, monetary assets is less than $3000 assets = value is 10800

    Code:
    if(fieldname16 < 2 && fieldname20 == Yes && fieldname2 >= 15000 && fieldname2 <=35000 && fieldname3 < 6000) return 10800;

    e)
    Condition:
    If one person household, with NO finance plan, annual income is more than $35,000, monetary assets is less than $3000 assets = value is 11000

    Code:
    if(fieldname16 < 2 && fieldname20 == No && fieldname2 < 35000 && fieldname3 < 3000) return 11000;

    f)
    Condition:
    If one person household, with a finance plan, annual income is more than $35,000, monetary assets is less than $3000 assets = value is 13200

    Code:
    if(fieldname16 < 2 && fieldname20 == Yes && fieldname2 < 35000 && fieldname3 < 3000) return 13200;

    g)
    Condition:
    If married or two person household, with NO finance plan, annual income is less than $25000 and monetary assets is less than $5000 assets = value is 7000

    Code:
    if(fieldname16 > 1 && fieldname ==Yes fieldname20 == No && fieldname2 < 25000 && fieldname3 < 5000) return 7000;

    h)
    Condition:
    If married or two person household, with a finance plan, annual income is less than $25000 and monetary assets is less than $5000 assets = value is 8400

    Code:
    if(fieldname15 == Married || fieldname16 > 1 && fieldname20 == Yes && fieldname2 < 25000 && fieldname3 < 5000) return 7000;

    i)
    Condition:
    If married or two person household, with NO finance plan, annual income is between $25000 and $50000, monetary assets is less than $10000 assets = value is 9000

    Code:

    if(fieldname15 == Married || fieldname16 > 1 && fieldname20 == No && fieldname2 >= 25000 && fieldname2 <= 50000 && fieldname3 < 5000) return 9000;

    j)
    Condition:
    If married or two person household, with a finance plan, annual income is between $25000 and $50000, monetary assets is less than $10000 assets = value is 10800

    Code:

    if(fieldname15 == Married || fieldname16 > 1 && fieldname20 == Yes && fieldname2 >= 25000 && fieldname2 <= 50000 && fieldname3 < 10000) return 10800;

    k)
    Condition:
    If married or two person household, with NO finance plan, annual income is more than $50000, monetary assets is more than $10000 assets = value is 11000

    Code:
    if(fieldname15 == Married || fieldname16 > 1 && fieldname20 == No && fieldname2 > 50000 && fieldname3 > 10000) return 11000;

    l)
    Condition:
    If married or two person household, with a finance plan, annual income is more than $50000, monetary assets is more than $10000 assets = value is 13200

    Code:
    if(fieldname15 == Married || fieldname16 > 1 && fieldname20 == Yes && fieldname2 > 50000 && fieldname3 > 10000) return 13200;

    **Objective: All in one Calculation so all conditions are met and a value is given to the user.

    Thanks everybody!

Viewing 15 replies - 1 through 15 (of 16 total)
  • Thread Starter aesch777

    (@aesch777)

    Also, for reference from what I was working on:

    For one person household…
    Level 1: Annual Income is Less Than $15,000 (and less than $3,000 assets)
    without financing = $7,000
    with financing $8,400

    Level 2: Annual Income: $15,000-$35,000 (and less than $6,000 assets)
    without financing = $9,000
    with financing $10,800

    Level 3: More than $35,000 (or more than $6,000 assets)
    without financing = $11,000
    with financing $13,200

    For Married or two or more person household…
    Level 1: Annual Income is Less Than $25,000 (and less than $5,000 assets)
    without financing = $7,000
    with financing $8,400

    Level 2: Annual Income: $25,000-$50,000 (and less than $10,000 assets)
    without financing = $9,000
    with financing $10,800

    Level 3: More than $50,000 (or more than $10,000 assets)
    without financing = $11,000
    with financing $13,200

    Plugin Author codepeople

    (@codepeople)

    Hello,

    I’ll try to explain the issues taking as reference one of cases:

    h)
    Condition:
    If married or two person household, with a finance plan, annual income is less than $25000 and monetary assets is less than $5000 assets = value is 8400

    Your code:
    if(fieldname15 == Married || fieldname16 > 1 && fieldname20 == Yes && fieldname2 < 25000 && fieldname3 < 5000) return 7000;

    There are some issues in your code.

    First, the texts in javascript must be enclosed between single or double quotes.

    Second, the precedence of AND is higher than OR.

    So, the correct condition would be:

    if((fieldname15 == 'Married' || fieldname16 > 1) && fieldname20 == 'Yes' && fieldname2 < 25000 && fieldname3 < 5000) return 8400;

    Best regards.

    • This reply was modified 6 years, 11 months ago by bdbrown.
    Thread Starter aesch777

    (@aesch777)

    Hi I changed it to this, however it is still not working.

    if((fieldname15 == ‘Single’ ||fieldname16 < 2) && fieldname20 == ‘No’ && fieldname2 < 15000 && fieldname3 < 3000) return 7000; 
    
    if((fieldname15 == ‘Single’ || fieldname16 < 2) && fieldname20 == ‘Yes’ && fieldname2 < 15000 && fieldname3 < 3000) return 8400; 
    
    if((fieldname15 == ‘Single’ || fieldname16 < 2) && fieldname20 == ‘No’ && fieldname2 >= 15000 && fieldname2 <=35000 && fieldname3 < 6000) return 9000; 
    
    if((fieldname15 == ‘Single’ || fieldname16 < 2) && fieldname20 == ‘Yes’ && fieldname2 >= 15000 && fieldname2 <=35000 && fieldname3 < 6000) return 10800; 
    
    if((fieldname15 == ‘Single’ || fieldname16 < 2) && fieldname20 == ‘No’ && fieldname2 < 35000 && fieldname3 < 3000) return 11000; 
    
    if((fieldname15 == ‘Single’ || fieldname16 < 2) && fieldname20 == ‘Yes’ && fieldname2 < 35000 && fieldname3 < 3000) return 13200; 
    
    if((fieldname15 == ‘Married’ || fieldname16 > 1) && fieldname20 ==’Yes’ fieldname20 == No && fieldname2 < 25000 && fieldname3 < 5000) return 7000; 
    
    if((fieldname15 == ‘Married’ || fieldname16 > 1) && fieldname20 == ‘Yes’ && fieldname2 < 25000 && fieldname3 < 5000) return 8400; 
    
    if((fieldname15 == ‘Married’ || fieldname16 > 1) && fieldname20 == ‘No’ && fieldname2 >= 25000 && fieldname2 <= 50000 && fieldname3 < 5000) return 9000; 
    
    if((fieldname15 == ‘Married’ || fieldname16 > 1) && fieldname20 == ‘Yes’ && fieldname2 >= 25000 && fieldname2 <= 50000 && fieldname3 < 10000) return 10800; 
    
    if((fieldname15 == ‘Married’ || fieldname16 > 1) && fieldname20 == ‘No’ && fieldname2 > 50000 && fieldname3 > 10000) return 11000; 
    
    if((fieldname15 == ‘Married’ || fieldname16 > 1) && fieldname20 == ‘Yes’ && fieldname2 > 50000 && fieldname3 > 10000) return 13200;

    [Moderator note: code fixed. Please wrap code in the backtick character or use the code button.]

    • This reply was modified 6 years, 11 months ago by bdbrown.
    Plugin Author codepeople

    (@codepeople)

    Hello @aesch777,

    If you have multiple conditional statements, you should define the equation with a function structure:

    (function(){
    /** YOUR CODE HERE **/
    })()

    Could you send me the link to the webpage where the form is inserted, please?

    Best regards.

    Thread Starter aesch777

    (@aesch777)

    Hi Yes I did include that:
    Link: https://sinplydeals.com/tuition-calculator/

    (function(){
    
    if((fieldname10 == ‘Single’ || fieldname5 < 2) && fieldname11 == ‘No’ && fieldname7 < 15000 && fieldname8 < 3000) return 7000; 
    
    if((fieldname10 == ‘Single’ || fieldname5 < 2) && fieldname11 == ‘Yes’ && fieldname7 < 15000 && fieldname8 < 3000) return 8400; 
    
    if((fieldname10 == ‘Single’ || fieldname5 < 2) && fieldname11 == ‘No’ && fieldname7 >= 15000 && fieldname8 <=35000 && fieldname3 < 6000) return 9000; 
    
    if((fieldname10 == ‘Single’ || fieldname5 < 2) && fieldname11 == ‘Yes’ && fieldname7 >= 15000 && fieldname8 <=35000 && fieldname3 < 6000) return 10800; 
    
    if((fieldname10 == ‘Single’ || fieldname5 < 2) && fieldname11 == ‘No’ && fieldname7 < 35000 && fieldname8 < 3000) return 11000; 
    
    if((fieldname10 == ‘Single’ || fieldname5 < 2) && fieldname11 == ‘Yes’ && fieldname7 < 35000 && fieldname8 < 3000) return 13200; 
    
    if((fieldname10 == ‘Married’ || fieldname5 > 1) && fieldname11 == ‘No’ && fieldname7 < 25000 && fieldname8 < 5000) return 7000; 
    
    if((fieldname10 == ‘Married’ || fieldname5 > 1) && fieldname11 == ‘Yes’ && fieldname7 < 25000 && fieldname8 < 5000) return 8400; 
    
    if((fieldname10 == ‘Married’ || fieldname5 > 1) && fieldname11 == ‘No’ && fieldname7 >= 25000 && fieldname7 <= 50000 && fieldname8 < 5000) return 9000; 
    
    if((fieldname10 == ‘Married’ || fieldname5 > 1) && fieldname11 == ‘Yes’ && fieldname7 >= 25000 && fieldname7 <= 50000 && fieldname8 < 10000) return 10800; 
    
    if((fieldname10 == ‘Married’ || fieldname5 > 1) && fieldname11 == ‘No’ && fieldname7 > 50000 && fieldname8 > 10000) return 11000; 
    
    if((fieldname10 == ‘Married’ || fieldname5 > 1) && fieldname11 == ‘Yes’ && fieldname7 > 50000 && fieldname8 > 10000) return 13200;
    
    })()

    [Moderator note: code fixed. Please wrap code in the backtick character or use the code button.]

    • This reply was modified 6 years, 11 months ago by bdbrown.
    Plugin Author codepeople

    (@codepeople)

    Hello @aesch777,

    The issues in your equation are simple.

    First, you are using wrong single quote symbols ‘’, but the single quotes symbols supported by javascript are: ''

    Second, for yes/no fields I recommend you the use of radio buttons instead checkbox, because the checkboxes allow multiple selections.

    Pay attention: If you decide replace the fields, then you should replace their names in the equation too.

    Best regards.

    Thread Starter aesch777

    (@aesch777)

    Hi! Thank you so much for the help.

    I will keep the suggestion to use radio buttons in mind.

    I am still stuck on a couple conditions with Multiple Or’s / And’s

    Condition:

    If one person household OR single, with NO finance plan, AND annual income is more than $35,000, OR monetary assets is More than $6000 assets = value is 11000

    Code So Far:
    if((fieldname10 == 'Single' || fieldname5 < 2) && fieldname11 == 'No' && fieldname7 > 35000 || fieldname8 > 6000) return 11000;

    [Moderator note: code fixed. Please wrap code in the backtick character or use the code button.]

    Thanks,

    • This reply was modified 6 years, 11 months ago by bdbrown.
    Plugin Author codepeople

    (@codepeople)

    Hello,

    The conditional rule in this case would be:

    if((fieldname10 == 'Single' || fieldname5 < 2) && fieldname11 == 'No' && (35000 < fieldname7 || 6000 < fieldname8)) return 11000;

    as I said in a previous ticket the precedence of the AND (&&) operator is higher the OR (||) operator, so, to increase the precedence should be used parentheses.

    Best regards.

    Thread Starter aesch777

    (@aesch777)

    I have to add another condition. fieldname57 will have choice values: a, b, c

    if everything is the same, and fieldname == a

    My code looks like this:

    if((fieldname10 == ‘Single’ || fieldname5 < 2) && fieldname11 == ‘No’ && (35000 < fieldname7 || 6000 < fieldname8) && fieldname57 == a) return 11000;

    I do not quite understand the placement of the parentheses still. Is there a guide or more examples?

    Thanks for your help!

    Plugin Author codepeople

    (@codepeople)

    Hello,

    First, in javascript the literal texts must be closed between single or double quotes, so, the correct condition would be:

    fieldname57 == 'a'

    Concerning the precedence of logical operators you can visit any of thousands javascript manuals available in the Internet, however, I think the following examples can help you to understand:

    The condition:

    if(3==3 || 1==1 && 2==1) is evaluated as true. The precedence of the “AND” operator is higher than the “OR”, so, first the is evaluated the condition 1==1 && 2==1 that evidently is false, and then, it is evaluated the condition if(3==3 || false) that returns true because 3==3.

    Now using parenthesis:

    if((3==3 || 1==1) && 2==1) first will be evaluated the conditions between parenthesis (the “OR” operator), whose result is true, and then the “AND” operator if(true && 2==1) that returns false. As you can see the use of parenthesis has raised the precedence of the “OR” operator forcing to evaluate it before the “AND”.

    Best regards.

    Thread Starter aesch777

    (@aesch777)

    What about in between numbers. For example, I want to make a condition of fieldname3 in between 3000 – 5999?

    Would both (fieldname3 >= 3000 && fieldname3 <= 5999)
    and (3000 <= fieldname3 && 5999 >= fieldname3)
    work?

    And, if I put all these conditions together in addition to fieldname57 == ‘a’

    What is wrong with my code here?

    if((fieldname49 == ‘Single’ || fieldname16 < 2) && fieldname50 == ‘No’ && fieldname2 < 15000 && (3000 <= fieldname3 && 6000 > fieldname3 ) && fieldname57 == ‘a’ ) return 8400;

    Plugin Author codepeople

    (@codepeople)

    Hello,

    Please, when you insert code in the forum, wrap code with the backtick character or use the code button, because I don’t know if you are using wrong single quote symbols ‘’ in your form (the single quotes symbols supported by javascript are: '') or if the symbols were converted by the forum.

    Concerning to the conditional statement, the structure is correct (there are some unnecessary parenthesis but don’t affect the result), but I don’t know if the conditions represent what you want:

    if((fieldname49 == 'Single' || fieldname16 < 2) && fieldname50 == 'No' && fieldname2 < 15000 && 3000 <= fieldname3 && fieldname3 < 6000 && fieldname57 == 'a' ) return 8400;

    I’m sorry, but the support service does not cover the implementation of the users projects (forms and formulas), if need I can give you some tips or instructions, or clarify some doubts you can have, but I cannot debug your project.

    Best regards.

    Thread Starter aesch777

    (@aesch777)

    Okay thank you I appreciate it. Tips and instructions help a lot ??

    I am hesitant on entering two fieldnames (fieldname 2 and 3) that have to be in between two numbers.

    The conditions I want are:
    -fieldname49 is married or fieldname > 1
    -fieldname 50 is No
    -fieldname2 is between 25,000 – 50,000
    -fieldname3 is between 5000 -10000
    -fieldname57 is a

    result: 6200

    Code so far:

    if((fieldname49 == ‘Married’ || fieldname16 > 1) && fieldname50 == ‘No’ && (fieldname2 < 25000 && fieldname2 <= 5000) && (5000 <= fieldname3 && fieldname3 < 10000) && fieldname57 == ‘a’ ) return 7200;

    Plugin Author codepeople

    (@codepeople)

    Hello @aesch777,

    I’m sorry, but if you need additional help implementing your equations, you should hire a custom coding service through my private website:

    https://cff.dwbooster.com/customization

    or hiring the support service if you have specific questions related with your project:

    https://cff.dwbooster.com/support-policy

    Best regards.

    Thread Starter aesch777

    (@aesch777)

    ??

    Okay thanks @codepeople for your support for the long thread. Have a good new years!

    All the best,

Viewing 15 replies - 1 through 15 (of 16 total)
  • The topic ‘If statements, Multiple Conditions, && and ||’ is closed to new replies.