### Post

2 followers Follow

# Need Help with a calculation please!

I have an app that needs to calculate the reimbursement paid to a swim instructor for low-income families.

The current formula that I have only works for CHILD 1.

var WR = @INSTRUCTOR WEEKLY RATE;
WR > 100 ? 50*@NUMBER OF WEEKS : WR < 101 ? WR*@NUMBER OF WEEKS/2 : ""

I need the same formula, but to include NUMBER OF WEEKS FOR CHILD 2, CHILD 3, CHILD 4 AND CHILD 5 and add the correct sum of up to the maximum number of children a family may have.

Thank you so much!

Armando

Armando Juarez

### 1 comment

Hello Armando,

you first need to calculate the total number of weeks of all children.

`var child1 = Number(@CHILD 1 NUMBER OF WEEKS) || 0;var child2 = Number(@CHILD 2 NUMBER OF WEEKS) || 0;var child3 = Number(@CHILD 3 NUMBER OF WEEKS) || 0;var child4 = Number(@CHILD 4 NUMBER OF WEEKS) || 0;var child5 = Number(@CHILD 5 NUMBER OF WEEKS) || 0;var totalWeeks = child1 + child2 + child3 + child4 + child5;var WR = @INSTRUCTOR WEEKLY RATE; WR > 100 ? 50*totalWeeks : WR < 101 ? WR*totalWeeks/2 : "";`

Please note: the category values (1,2,3,etc) are from a technical point of view not digits but text. So you can't simply "add" @CHILD 1 NUMBER OF WEEKS + @CHILD 2 NUMBER OF WEEKS - the result would two 2s = 22. So you first must parse the "text" to real numbers by: Number(@CHILD 1 NUMBER OF WEEKS).
|| 0 means: If there's no value (like in your example for child 4 and 5) set 0.
The parsing happens automatically if you combine a "real" number with a "text" number (like you do in TOTAL PARENT PAID).

Rainer