# Building a complex calculation in Storyline 2

I am trying to build a slide with a calculator but the formula at hand is more complex than simple addition/subtraction, etc. I hope someone in the community has had experience with something similar.

My goal is to have an effective annual rate calculator for the learner. The end result should be an interaction where the learner can put an annual percentage rate and a period (1= annual, 365 = daily) and click a button to obtain the EAR calculation.

I have two numeric entry fields, one for the APR variable and one for the Period variable. I also have a third variable for EAR as a placeholder.

This is the formula I am working with:

EAR = (1+APR/Periods) to the power of the 'periods'variable - 1.

Main questions:

1) can Articulate be set to perform this complex of a formula - i.e. raising a value to a power, multiple calculations?

2) is there a way to  convert the value of the variable to a decimal and keep it as such? I would need the APR percentage to do this for the formula to work. What I have done is set the APR value to be divided by 100 when the user clicks outside of the box; the issue I am running into is that it divides by 100 EVERY tie a user clicks anywhere outside of this box. Trying to figure out a way to lock this in on one click.

Any help is much appreciated! Thank you.

###### 3 Replies

To start with, SL does complex calculations, but you have to break them into steps. In your example, you would need a series of triggers, that fire one after the other, in the correct sequence when the user initiates the action. It isn't wise to change your original variables, always use them to change temp variables. So it would look something like this;

Adjust variable Total = Apr when user clicks Calculate button

Adjust Total / Periods when user clicks, etc.

Your first problem is that it is difficult to format decimal numbers in SL (understandably, it's presentation software, not calculating or programming software).

Add 1 to variable Total

tempPeriods  = period -1  **

Total raise to tempPeriods, and this is where your biggest problem is: powers. Like many questions in the computer world, the whole answer is, "Yes, you can do that, but you may not like what it will cost you." If you want to pay the price, here is how to do it, assuming that the only choices for period are 1, 12, and 365. Create 364 identical blank layers. Set them to hide other layers, and to pause the base timeline. I'd name them 1, 2, etc. Put these triggers on 364; "Adjust Total * Total when timeline starts", and "jump to slide 363 when timeline reaches .01". I wouldn't make the jump when timeline starts, I'd build in a little delay just to be sure the calculation is finished.

**After the other calculation variables, the final one (to raise to the power) would be "Show layer 364 if period = 365" followed by "Show layer 11 if period = 12".

You may find it easier to execute javascript when the user clicks the calculate button.

An additional advantage of js is that you can format the answer, and if you pass it back to SL to a text variable, it will keep the formatting.

Thank you, Walt. I appreciate your quick response and explanation! Given the price, as you call it, I am not sure that in this case the result would be worth the effort but it is great to know this is possible for future endeavors!

Many thanks!

Was trying to do something similar though a bit simpler...looks as though the real answer to the original question is NO....better to get the javascript out!