Break it down into a sequence of steps.
- Multiplication is as straightforward as it gets:
I*(1+I)
- Division is the same:
I/(1+I)
- To the power of
n
is denoted by: Math.pow(3, 5); //3 to the power of 5
Math.pow()
might be the only thing you didn't know yet.
Unrelated but useful,
Wrap your formula into a function and you have a mortgage-calculation function
calculateMortgage(p,i,n) {
result = //translate the formula in the way I indicated above
return result;
}
and call it like so:
var mortgage = calculateMortgage(300,3,2); // 'mortgage' variable will now hold the mortgage for L=300, I=3, N=2
Also, the formula you posted really doesn't make any sense - why is there a blank between P
& I
at the very beginning? Something's missing.