• Resolved Timur

    (@megashape)


    Hi there, I am trying to print a different number based on the entry in another field.

    This is what I used:

    (function(){
    
    IF(fieldname4==18,62.4);
    IF(fieldname4==19,61.5);
    IF(fieldname4==20,60.5);
    IF(fieldname4==21,59.5);
    IF(fieldname4==22,58.6);
    IF(fieldname4==23,57.6);
    IF(fieldname4==24,56.7);
    IF(fieldname4==25,55.7);
    
    })()

    This doesn’t return the values I want. What is my mistake?

    Thank you.

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

    (@codepeople)

    Hello @megashape

    First, you are not using the “IF” operation as should. The structure of the “IF” operation (JavaScript is a case sensitive programming language, do not confuse the “IF” operation in the plugin with the “if” conditional statement of javascript) is:

    
    IF(condition, operation if condition is true, operation if condition is false)
    

    In your case it is preferred the use of the conditional statements, as follows:

    
    (function(){
    
    if(fieldname4==18) return 62.4;
    if(fieldname4==19) return 61.5;
    if(fieldname4==20) return 60.5;
    if(fieldname4==21) return 59.5;
    if(fieldname4==22) return 58.6;
    if(fieldname4==23) return 57.6;
    if(fieldname4==24) return 56.7;
    if(fieldname4==25) return 55.7;
    
    })()
    

    or even better:

    
    (function(){
    
    switch(fieldname4){
    case 18: return 62.4;
    case 19: return 61.5;
    case 20: return 60.5;
    case 21: return 59.5;
    case 22: return 58.6;
    case 23: return 57.6;
    case 24: return 56.7;
    case 25: return 55.7;
    }
    
    })()
    

    Best regards.

Viewing 1 replies (of 1 total)
  • The topic ‘Multiple IF Statements Don’t Work’ is closed to new replies.