I have formula for finding monthly payment with four fields
Here is mine,
the formula :
M = P [ i(1 + i)^n ] / [ (1 + i)^n – 1]
nerdWallet
Hope this helps in someway
var M; //monthly mortgage payment
var P = 400000; //principle / initial amount borrowed
var I = 3.5 / 100 / 12; //monthly interest rate
var N = 30 * 12; //number of payments months
//monthly mortgage payment
M = monthlyPayment(P, N, I);
console.log(M);
function monthlyPayment(p, n, i) {
return p * i * (Math.pow(1 + i, n)) / (Math.pow(1 + i, n) - 1);
}