2 Replies Latest reply on Nov 20, 2012 12:06 PM by ahlaj77

# Help with conditional statement if/else (image included)

Hello to all!

Trying to get my if/else statement to work but its not working :/. I need a second opinion and how I can make it work. This code will be going in the Total Price column (where it says \$0.00). Thank you in advance!

Here is what I am trying to accomplish:

1. If the units are below 150 then no discount is applied.
2. If the units are 150-299 then apply a 40% discount.
3. If the units are 300+ then apply a 50% discount.

var v1 = this.getField("txtDoughUnit1").value;
var total = v1 * 14;

if(150 > total) event.value = total;

else if((total >= 150 ) && (total < 300)) event.value = total * 0.40;

else if(300 >= total) event.value = total * 0.50;

else event.value = 0;

• ###### 1. Re: Help with conditional statement if/else (image included)

What is not working in your script?

Check your comparison operator for the units below 150.

I would use the "switch" statement.

// units for computing discount

var nTotal = this.getField("txtDoughUnit1").value * 14;

// select when statement is true

switch(true) {

case (nTotal >= 300) :

// total greater than 300

event.value = nTotal * 0.50;

break; // end greater than 300

case (nTotal >= 150 ) :

// total greater than or equal to 150 and less than 300

event.value = nTotal * 0.40;

break; // end greater than or equal to 150, greater than 300 all ready done

default:

// all other values

event.value = 0;

break;

} // end of switch decision