.sum
.sub
.multiply
.divide
.store
The first four operators perform a calculation (add, subtract, multiply, divide) on a numeric question answer, and the .store operator is used to save the result in another question's answer. For example:
.sum(Q(10), Q(20), Q(30)) // add questions 10, 20 and 30 .store(Q(40)); // and store the result in question 40
.divide (Q(50), 4)) // divide the answer to question 50 by 4 .store (Q(60)); // and store the result in question 60
.store
ifQ(21) .answered() .andQ(31) .answered() .sum(Q(21), Q(31)) // add these responses .store(Q(41)); // and write them here
.sum
ifQ(21) .answered() .andQ(31) .answered() .sum(Q(21), Q(31)) // add these responses .store(Q(41)); // and write them here
// or literal numbers can be used
// .sum(Q(21), 4)
.sub
ifQ(21) .answered() .andQ(31) .answered() .sub(Q(21), Q(31)) // subtracts 31 from 21 .store(Q(41)); // and write it here
// can also use literal numbers
// .sub(Q(21), 2);
.multiply
ifQ(21) .answered(1) .multiply(Q(31), Q(41)) .store(Q(81));
// can also use literal numbers
// .multiply(Q(31), 1.0875)
.divide
ifQ(31) .answered() .divide(Q(31), 4) // 25% of the response to Q(31) .store(Q(81));
// can also use Questions
// .divide(100, Q(51));