Loan Amortization Calculator
1. Dashboard (Schedule & Summary)
2. Data Configuration (Inputs)
Loan Summary
Loan Details: Amount: $50,000.00 | Rate: 5.00% | Term: 5 Years
Monthly Payment
$0.00
Total Principal Paid
$0.00
Total Interest Paid
$0.00
Total Repayment Amount
$0.00
Amortization Schedule
Please enter the loan details in the **Data Configuration (Inputs)** tab and click 'Calculate' to generate the schedule.
| Month | Payment | Principal | Interest | Remaining Balance |
|---|
Error: Tool failed to load. Please check element IDs.
'; return; } // Helper to format currency (USD $) const currencyFormatter = new Intl.NumberFormat('en-US', { style: 'currency', currency: 'USD', minimumFractionDigits: 2, maximumFractionDigits: 2, }); const percentFormatter = new Intl.NumberFormat('en-US', { minimumFractionDigits: 2, maximumFractionDigits: 2, }); function formatCurrency(amount) { // II. D. 3. Default Currency: US Dollar ($) return currencyFormatter.format(amount); } // II. B. Tab Navigation Logic const tabs = ['dashboard', 'config']; let currentTabIndex = 0; function updateNavButtons() { prevBtn.disabled = currentTabIndex === 0; nextBtn.disabled = currentTabIndex === tabs.length - 1; // Minor visual styling for disabled buttons prevBtn.style.opacity = prevBtn.disabled ? '0.5' : '1'; nextBtn.style.opacity = nextBtn.disabled ? '0.5' : '1'; } window.switchTab = function(tabName) { const activeTab = document.querySelector('.tab-button.active'); const activeContent = document.querySelector('.tab-content.active'); const nextTabBtn = document.getElementById('tab-btn-' + tabName); const nextTabContent = document.getElementById('tab-content-' + tabName); if (!nextTabBtn || !nextTabContent) return; if (activeTab) activeTab.classList.remove('active'); if (activeContent) activeContent.classList.remove('active'); nextTabBtn.classList.add('active'); nextTabContent.classList.add('active'); currentTabIndex = tabs.indexOf(tabName); updateNavButtons(); }; window.navigateTabs = function(direction) { const newIndex = currentTabIndex + direction; if (newIndex >= 0 && newIndex < tabs.length) { switchTab(tabs[newIndex]); } }; // II. A. Functionality: Main Calculation Logic window.calculateAmortizationAndSwitchToDashboard = function() { const P = parseFloat(document.getElementById('loan-amount-input').value); // Principal const R_annual = parseFloat(document.getElementById('annual-rate-input').value); // Annual Rate (%) const Y = parseInt(document.getElementById('loan-term-input').value); // Years // Basic input validation if (isNaN(P) || isNaN(R_annual) || isNaN(Y) || P <= 0 || R_annual < 0 || Y <= 0) { alert("Please enter valid, positive numbers for all loan inputs."); return; } // Calculate Monthly Rate (r) and Total Number of Payments (n) const r = R_annual / 100 / 12; // Monthly interest rate const n = Y * 12; // Total number of months/payments let M; // Monthly Payment if (r === 0) { // Case where interest rate is 0% M = P / n; } else { // Standard Amortization Formula: M = P [ r(1 + r)^n ] / [ (1 + r)^n – 1] M = P * (r * Math.pow(1 + r, n)) / (Math.pow(1 + r, n) - 1); } let balance = P; let totalInterestPaid = 0; let scheduleHTML = ''; for (let month = 1; month <= n; month++) { // Calculate interest for the current month const interestPayment = balance * r; // Calculate principal portion let principalPayment = M - interestPayment; // Handle last payment adjustments if (month === n) { // Adjust the final principal/payment to zero out the balance precisely principalPayment = balance; M = interestPayment + principalPayment; balance = 0; } else { // Update balance for the next month balance -= principalPayment; if (balance < 0) { // Safety check for rounding issues on the last payment before the intended last month principalPayment += balance; // Correct principal to exactly zero out M = interestPayment + principalPayment; balance = 0; } } totalInterestPaid += interestPayment; // Generate table row for the schedule scheduleHTML += `