# Help with formula in javascript - figuring monthly payment

I know I must just be missing something really obvious, but this formula is coming up with a number close to accurate, but not quite - which is driving me nuts. What am I doing wrong?

I’m trying to have my script figure the monthly payments for a fixed-rate loan. I’m using (I think) a pretty standard formula:

Which I put into my script like this:

`var m = l * ( (r * ((1 + +r)^360)) / (((1 + +r)^360) - 1) );`

My variables have been defined earlier, some by user inputs, and are accurately displayed on the webpage so they seem to be working:

l = P above, loan total (starting principle) = 385000
r = r above, rate ([interest rate / 100] / 12) = 0.00315
360 = n above, loan periods (30 years * 12 months)

When I run it, it spits out “m” (A above) as 1206. It should be 1783. ??!!!

Any help would be greatly appreciated. Thank you!

The actually monthly payment amount would be \$1789.56 not \$1783.

`var e = Math.pow((1 + +r), 360);`
`var m = l * ( (r * e) / (e - 1) );`