• Resolved gregorr64

    (@gregorr64)


    Hi,

    Is it possible to use If And statements?

    For example:

    (function(){
    if(fieldname35 < 900) return 0;
    if(fieldname35 < 1800 AND fieldname35 >=900) return 50;
    if(fieldname35 < 2700 AND fieldname35 >=1800) return 100;
    if(fieldname35 < 3600 AND fieldname35 >=2700) return 150;
    if(fieldname35 > 3600) return 99999;
    })();

    This isn’t returning any value, what have I done wrong?

    Thanks,
    Gregor

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

    (@codepeople)

    Hello @gregorr64,

    In javascript the “AND” operator is the double ampersand: &&:

    
    (function(){
    if(fieldname35 < 900) return 0;
    if(900 <= fieldname35 && fieldname35 < 1800) return 50;
    if(1800 <= fieldname35 && fieldname35 < 2700) return 100;
    if(2700 <= fieldname35 && fieldname35 < 3600) return 150;
    if(3600 <= fieldname35) return 99999;
    })();
    

    However, as you are using “return” instructions with each “if”, checking for intervals is unnecessary, and the same is happening with the last “if” statement that includes all other alternatives.

    So, the equation can be implemented simply as follows:

    
    (function(){
    if(fieldname35 < 900) return 0;
    if(fieldname35 < 1800) return 50;
    if(fieldname35 < 2700) return 100;
    if(fieldname35 < 3600) return 150;
    return 99999;
    })();
    

    Best regards.

    Thread Starter gregorr64

    (@gregorr64)

    Ahhh right, gotcha. That makes a lot more sense.

    Thanks,
    Gregor

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘IF AND Statements’ is closed to new replies.