Amortization Schedule
| Payment # |
Principal |
Interest |
Total Payment |
Balance |
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) || 0;
if (isNaN(loanAmount) || isNaN(interestRate) || isNaN(loanTerm) || loanAmount <= 0 || interestRate <= 0 || loanTerm 0) {
paymentNumber++;
const interestPayment = balance * interestRate;
const principalPayment = adjustedMonthlyPayment – interestPayment;
balance -= principalPayment;
totalInterestPaid += interestPayment;
if (balance < 0) balance = 0; // Avoid negative balance
scheduleRows += `
| ${paymentNumber} |
${principalPayment.toFixed(2)} |
${interestPayment.toFixed(2)} |
${adjustedMonthlyPayment.toFixed(2)} |
${balance.toFixed(2)} |
`;
if (balance === 0) break;
}
// Display results
document.getElementById(‘monthlyPayment’).value = adjustedMonthlyPayment.toFixed(2);
document.getElementById(‘totalInterestPaid’).value = totalInterestPaid.toFixed(2);
document.getElementById(‘scheduleTable’).getElementsByTagName(‘tbody’)[0].innerHTML = scheduleRows;
document.getElementById(‘amortizationResults’).style.display = ‘block’;
}