5 Replies Latest reply on May 15, 2015 1:45 AM by try67

# Logic problem to divide from total

I'm attempting to subract a value from a total, and then divide from that total to find out how many questions a person got wrong (every question assigned a value of 4)

and I cannot seem to wrap my head around the plain english script i need to use. I know its staring at me in the face.

var DEDUCTION = this.getField("TOTAL").value;
if ( TOTAL = 100 ) event.value = "0";

else if ( TOTAL < 100 ) event.value = TOTAL - 100 / -4;

it always displays as 0. Am I off my rockers thinking that this is correct script?

• ###### 1. Re: Logic problem to divide from total

I'm not sure about the logic behind it, but this line is wrong:

if ( TOTAL = 100 ) event.value = "0";

The comparison operator is "==", not "=". So it should be:

if ( TOTAL == 100 ) event.value = "0";

Also, you don't really need that line because if the total is 100 the calculation will be (100-100)/-4, which is zero anyway...

• ###### 2. Re: Logic problem to divide from total

JavaScript syntax has different operators for assignment of a value and  comparison operators..

The "=" is a simple assignment operator. There are additional for operators adding, subtracting, multiplying, dividing, and remainder assignment by another value as well as bit assignment operators.

The "==" is the simple value comparison operator. There are additional comparisons for Boolean comparisons.

• ###### 3. Re: Logic problem to divide from total

I am learning this whole process as I work along =) Trying to read up as I go from one thing to the next. I've negated that redundant line, thanks for the help.

• ###### 4. Re: Logic problem to divide from total

As a follow up question, I have redone the script to display the proper value, but now it wont appear?

I've even redone the script to do a simple addition problem, but it wont display. Its set to the last field calculation. Not sure why it is doing this.

• ###### 5. Re: Logic problem to divide from total

Open the JS Console (Ctrl+J) and check if there are any error messages.