Amortization Calculator with Extra Monthly

Amortization Calculator with Extra Monthly Payments

Amortization Results:

Monthly Payment:

Total Interest Paid:

Loan Paid Off in: years

function calculateAmortization() { const loanAmount = parseFloat(document.getElementById(‘loanAmount’).value); const interestRate = parseFloat(document.getElementById(‘interestRate’).value) / 100 / 12; const loanTerm = parseInt(document.getElementById(‘loanTerm’).value) * 12; const extraPayment = parseFloat(document.getElementById(‘extraPayment’).value); if (isNaN(loanAmount) || isNaN(interestRate) || isNaN(loanTerm) || isNaN(extraPayment)) { alert(“Please enter valid values.”); return; } // Monthly payment calculation const monthlyPayment = (loanAmount * interestRate) / (1 – Math.pow(1 + interestRate, -loanTerm)); const totalMonthlyPayment = monthlyPayment + extraPayment; // Calculate loan payoff time and interest let remainingBalance = loanAmount; let monthsToPayOff = 0; let totalInterest = 0; while (remainingBalance > 0) { let interestPayment = remainingBalance * interestRate; let principalPayment = totalMonthlyPayment – interestPayment; remainingBalance -= principalPayment; totalInterest += interestPayment; monthsToPayOff++; if (remainingBalance < 0) remainingBalance = 0; } const totalPaid = monthsToPayOff * totalMonthlyPayment; const yearsToPayOff = monthsToPayOff / 12; // Update results document.getElementById('monthlyPayment').textContent = `$${totalMonthlyPayment.toFixed(2)}`; document.getElementById('totalInterest').textContent = `$${totalInterest.toFixed(2)}`; document.getElementById('loanTermWithExtra').textContent = yearsToPayOff.toFixed(2); } function resetAmortization() { document.getElementById('amortization-form').reset(); document.getElementById('amortization-result').style.display = 'none'; }

Leave a Reply

Your email address will not be published. Required fields are marked *