Debt Information
Summary
Initial Balance
$10,000
APR
21.0%
Monthly Payment
$300
Payoff Time
-
Total Interest Paid
$0
Payoff Rating
-
Debt Payoff Progress Chart
Enter debt information to see payoff chart
Enter debt information to see payoff chart
';
return;
}
// Create chart HTML
let chartHTML = 'Remaining Balance Over Time
';
// Y-axis labels
chartHTML += '';
for (let i = 0; i <= 5; i++) {
const value = initialBalance * (1 - i / 5);
chartHTML += `
';
// Chart content container
chartHTML += '${Math.round(value).toLocaleString()}
`;
}
chartHTML += '';
// Create bars - sample the data for better visualization
const maxBars = 50;
const step = Math.max(1, Math.ceil(schedule.length / maxBars));
for (let i = 0; i < schedule.length; i += step) {
const point = schedule[i];
const heightPercent = (point.remainingBalance / initialBalance) * 100;
chartHTML += `
`;
}
chartHTML += '
'; // Close chart-content
// X-axis labels
chartHTML += '';
chartHTML += '
';
chartContainer.innerHTML = chartHTML;
}
function exportToCSV() {
const schedule = calculateSchedule();
if (schedule.length === 0) {
alert('Please enter valid debt information to export schedule');
return;
}
const initialBalance = parseFloat(document.getElementById('initialBalance').value);
const apr = parseFloat(document.getElementById('apr').value);
let csv = 'Initial Balance,APR,Month,Payment Amount,Interest Paid,Principal Paid,Remaining Balance,Total Interest Paid\n';
schedule.forEach((row, index) => {
const initialBal = index === 0 ? initialBalance : '';
const aprVal = index === 0 ? apr + '%' : '';
csv += `${initialBal},${aprVal},${row.month},$${row.paymentAmount.toFixed(2)},$${row.interestPaid.toFixed(2)},$${row.principalPaid.toFixed(2)},$${row.remainingBalance.toFixed(2)},$${row.totalInterest.toFixed(2)}\n`;
});
const blob = new Blob([csv], { type: 'text/csv' });
const url = window.URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = 'debt-payoff-schedule.csv';
a.click();
window.URL.revokeObjectURL(url);
}
// Event listeners
document.getElementById('initialBalance').addEventListener('input', updateDisplay);
document.getElementById('apr').addEventListener('input', updateDisplay);
document.getElementById('monthlyPayment').addEventListener('input', updateDisplay);
// Initial calculation
updateDisplay();
Start
';
chartHTML += `${Math.floor(schedule.length/2)} months
`;
chartHTML += `${schedule.length} months
`;
chartHTML += '
