3 Replies Latest reply on Sep 30, 2016 6:08 AM by rsbisa

# IF / AND statement question

when using an if(  ) && ( ) statement, is it permissible to test for two different conditions. Meaning, can I say, "If the apple is red, and if the car is blue, then..."? Or, does it have to be something like, "If the apple is red and the apple is large"?

The below code is not working as I would like, and I'm wondering if the problem is the && statement.

Situation: There are two classes. Class I and Class 2 ("Title"). Class I gets life insurance at 3x annual income, up to \$1,500,000. Class 2 gets life insurance at 3x annual income, up to \$600,000. I have a dropdown list, "Title", with Class I and Class II to select, (returning 1 or 2). The calculable field is suppose to return the life insurance death benefit, depending on the conditions of the class and income. It is ignoring Class 2. In other words, I can type any amount of income when Class 2 is selected and the death benefit will blow past 600,000 and go all the way to 1,500,000.

Is my problem the way I'm using &&?

var a1 = getField("Income").value;   //annual income

var a2 = getField("Title").value;   //job class; either 1 or 2 numeric value

var v1 = a1*3;   //life insurance is 3x annual income

//if Class I and life insurance amount is < 1500000, then 3x annual income

if((a2 = 1) && (v1 < 1500000)) event.value = v1;

//if Class I and life insurance is > 1500000, then 1500000 (the max)

else if((a2 = 1) && (v1 > 1500000)) event.value = 1500000;

//if Class I and life insurance amount is < 600000, then 3x annual income

else if((a2 = 2) && (v1 < 600000)) event.value = v1;

//if Class I and life insurance amount is > 600000, then 600000 max

else if((a2 = 2) && (v1 > 600000)) event.value = 600000;

Thanks for any help!

• ###### 1. Re: IF / AND statement question

if((a2 = 1) && (v1 < 1500000)) event.value = v1;

Do this:

if ((a2 == 1) && (v1 < 1500000)) event.value = v1;

in all cases, and that should fix it.