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:
Topequals 1 +MonthlyInterestRate,Topis set toTopto the power ofnprTopis set toTopmultiplied byMonthlyInterestRateBottomequals 1 +MonthlyInterestRate,Bottomis set toBottomto the power ofnprminus 1- then finally the result of
Topdivided byBottomis 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
