Variable Tutorial with Calculations

I was watching a tutorial by Jeanette titled Adding Data Entry Fields. The tutorial did a great job of showing how to enter text fields. The example she used also showed how it is possible to have some numberical entries for the user and at the end it would calculate a result.

The example was about a 401(K) plan and how the employee could enter a dollar amount, number of years and a percentage to get a result. Is there a tutorial that covers a similar type of calculation?

I did look at the tutorial for Adding Number Variables but it only demonstrated how to assign a numerical value for a choice. It did not show how to do a calculation.

Thanks for the tutorials and I hope there is one for calculations or that you can make one.

Jeffrey Riley

16 Replies
Jeanette Brooks

Hi Jeffrey! I did a quick screenr on how the calculation slide was built, but maybe it would help to also take a peek at the slide itself so you can deconstruct:


Published demo

Source file

The slide asks the learner to enter 3 items: their salary, the percent they plan to contribute to their 401k, and the number of years till retirement. When they click the Calculate button, a layer appears which shows them the total amount of matching funds the company will contribute on their behalf.

Here's the logic behind the calculations: 

  • I create a variable called Match Calc which is used to display the total on the Results layer. I also created variables for the match percent, salary, and years till retirement.
  • I have a trigger on the base layer which initially sets my Match Calc value equal to the salary, but then on the results layer we perform some calculations on that number to get to the final result.
  • When the learner hits the Calculate button, triggers on the Results layer take the salary, multiply it by the matching percentage, and then multiple by the number of years till retirement. 

I also have a different layer which pops up if the learner tries to hit the Calculate button without entering all the required information.

I hope that helps!

David Lindenberg

Thanks for asking the question Jeffrey and thanks for the example Jeanette.

I built a similar tool and I have it working fine.  The user enters 3 numbers and they perform the calculation.  Is there a way to reset the fields so that they can try again with different numbers?  Ideally I'd like them to click a Reset(!) button so it clears the values and they can play with as many numbers as they want.

Jeanette Brooks

Hi David! Phil's idea is a good one - if your interaction is like the the 401k example posted above, you could perhaps add some triggers to the "Thanks" button on the layer called Results. That way, learners could close the layer and reset the values all with one click. Here's how the triggers would look:

Ashley Terwilliger

Hi Brent, 

This thread is a bit older, so I'm not certain if folks are still subscribed so you may want to message them directly using the "contact me" button on their profile to see if they're able to share what they ended up doing. You may want to also look at investigating what options you have if you were to use Javascript to work with multiple decimal points in variables. It may be something the community can assist with, but you may want to begin by reviewing the best practices here. 

Leslie McKerchie

Hi Rakesh,

I just responded to your question here, and this conversation may shed a little more light on what you want to do.

Tracking in a text file or database is not something I can assist in supporting. As I mentioned in the other conversation, we recommend publishing to an LMS.

Hopefully, someone in the community will be able to chime in and help you out here.