Question: Trying to create a loan calculator based on two sliders. I feel I'm nearly there but the syntax is letting me down plus one last formula.

I have two sliders, one which represents the loan amount, the other represents the loan length.

Here is a bit of the code to highlight all the calculations. I think there are errors here too.

```
function update() {

     $amount = $("#slider1").slider("values", 100);

     $interest = $amount / 100 * 15 ;

     $perday = 15 ;      

     $apr = (($interest / $amount) / ("#slider2"/365) * 10000) / 100;

     $amount2 = $amount + $interest;

     $("#amount").val($amount1);

     $("#amount2").val($amount2);

     $("#amount3").val($interest);

}

```

Interest is charged at 15% of the amount borrowed.
Each day is worth 15p so in order to get my final charge. 

[15% of the loan amount total]
– [0.15p per day credit]

I have developed a fiddle but its not correct, hence why I'm here.

[Fiddle Here](http://jsfiddle.net/jonnystudent/VycW2/)

How can I get both the sliders to work together so that if I move the top or bottom slider, it will affect the overall loan amount and Interest?

Any help will be most appreciated. I'm really struggling with this one.

Answer: 
[***I believe this is what you want - jsfiddle***](http://jsfiddle.net/VycW2/17/) <- follow link

```
function update() {            
     $interest = 0.15 ;
     $perday = 15 ; 
     $amount1 = $("#amount").val();
     $dayscount = $("#days").val();
     $amount2 = parseInt($amount1) + $interest * parseInt($amount1) + (parseInt($dayscount) * ($perday/100));
     $("#amount2").val($amount2);
     $("#amount3").val(parseFloat($amount2-$amount1).toFixed(2));
}

```

Fixed your update algorithm and your slider handlers

I considered that you last 2 fields (Your Loan & Interest) are the final value to be paid and the difference between the value to be paid and the value borrowed respectively. If this interpretation is not what you intended please comment.

**UPDATE 1**

Here I updated the [jsfiddle](http://jsfiddle.net/VycW2/19/). Beware that I don't know what the APR is, so validate that my calculation are right. I also did not use any rounding, cause I don't know if you need it like this

**UPDATE 2**

Updated with new [**formula here**](http://jsfiddle.net/VycW2/20/). I still have no idea if this is right or not
If i understood you right, you could do something like this:

```
function update() {
    var interest = 0.15;
    var sliderAmount = parseFloat($("#slider1").slider("option", "value"));
    var days = parseFloat($("#slider2").slider("option", "value"));
    var perday = 15 * days ;
    var interestAmount = sliderAmount * interest * days;
    $("#amount1").val(sliderAmount);
    $("#amount2").val(sliderAmount);
    $("#amount3").val(interestAmount+ perday);
}

```