I have this code I am trying to translate into maths
var Top=1+MonthlyInterestRate; Top=Math.pow(Top,npr);' Top=MonthlyInterestRate*Top; var Bottom=1+MonthlyInterestRate; Bottom=Math.pow(Bottom,npr)-1; var MonthlyPayment=(PrincipalBalance*(Top/Bottom)).toFixed(2);
My basic problem is that the var ‘top’ is declared 3 times, so I don’t know how to reflect it mathematically.
var bottom is also declared twice, which value will be the final?
the first variable or the second?
Advertisement
Answer
JavaScript is imperative, instructions are executed from top to bottom. Here’s what happens, in order:
Top
equals 1 +MonthlyInterestRate
,Top
is set toTop
to the power ofnpr
Top
is set toTop
multiplied byMonthlyInterestRate
Bottom
equals 1 +MonthlyInterestRate
,Bottom
is set toBottom
to the power ofnpr
minus 1- then finally the result of
Top
divided byBottom
is multiplied byPrincipalBalance
A mathematical equation would be something along the lines of:
where a equals to PrincipalBalance
, b equals to MonthlyInterestRate
and c equals to npr