Reputation: 69
my code is suppose to calculate mortgage payments
var LA = 100000;
var RA=0.07;
var YA=30;
var R = ( RA / 12);
var r = (1 + R);
var Yr = (YA * 12);
var pay = (LA * Math.exp(r,Yr)*R)/(Math.pow(r,Yr)-1);
returns $224.12
which is wrong it needs to be $665.30 payment = [ LA * r^Yr * R ] / [ r ^Yr - 1]
For example:
30 year mortgage for $100,000 at 7% interest (0.07)
0.07 / 12 = 0.00583 (this is R)
30 * 12 = 360 (this is Yr)
1 + 0.00583 = 1.00583 (this is r)
payment = [ $100,000 * (1.00583)^360 * 0.00583 ] / [ (1.00583)^360 - 1 ]
Monthly Payments will be $665.30
any tips?
Upvotes: 0
Views: 3818
Reputation: 324650
Use the correct function: Math.pow
and not Math.exp
.
Also, although square brackets will work, it's only because JavaScript is casting the arrays to strings, and then to numbers. Use parentheses instead.
Upvotes: 3