Javascript to calculate what a slider displays

Oct 13, 2021

Hi everyone!

I want to use a slider that shows how compound interest works.  Where you could set the beginning balance and the interest rate and then the slider would use it, as it slid over time, to show a displayed value of total interest owed.

The equation would be:

Displayed Value = Beginning Balance * (1 + Interest Rate) ^ Time

Any idea how to do this using javascript or even triggers if possible?

Thanks in advance!

 

2 Replies
Judy Nollet

You don't need JavaScript.

First, create a number variable for each part of the equation. For easier programming, name them so it's obvious what they stand for.

  • When you insert a slider, SL automatically creates its variable. 
  • If you want the user to be able to calculate using any beginning balance and interest rate, insert Number data-entry fields to capture that info. If you do that, SL will automatically create those variables. However, if you want the user to select from a set of pre-defined balances and interest rates, you will have to create those variables manually. 
  • You will have to manually create a variable for the Displayed Value.

Use a series of triggers to adjust the Value variable by performing the calculations in the proper order. 

Display the final value by inserting a variable reference on the slide. 

For more info: