Future Value of Annuity Calculator - Professional Investment Growth Tool
Total Interest Earned
$0.00
`);
printWindow.document.close();
printWindow.focus();
setTimeout(() => {
printWindow.print();
printWindow.close();
}, 250);
this.showToast('PDF generated successfully!', 'success');
}resetForm() {
this.form.reset();
this.resultsSection.classList.remove('show');
window.history.replaceState({}, '', window.location.pathname);
// Reset toggle
document.querySelector('.toggle-option[data-value="end"]').click();
this.showToast('Form reset successfully', 'success');
}loadCalculation() {
if (this.savedCalculations.length === 0) {
this.showToast('No saved calculations found', 'warning');
return;
}
const latest = this.savedCalculations[this.savedCalculations.length - 1];
const data = latest.data;
// Populate form
document.getElementById('paymentAmount').value = data.paymentAmount;
document.getElementById('interestRate').value = (data.interestRate * 100).toFixed(2);
document.getElementById('timePeriod').value = data.timePeriod;
document.getElementById('paymentFrequency').value = data.paymentFrequency;
document.getElementById('compoundingFrequency').value = data.compoundingFrequency;
if (data.paymentTiming === 'beginning') {
document.querySelector('[data-value="beginning"]').click();
} else {
document.querySelector('[data-value="end"]').click();
}
// Submit form
setTimeout(() => this.form.dispatchEvent(new Event('submit')), 200);
this.showToast('Loaded last saved calculation', 'success');
}showError(message) {
const errorEl = document.getElementById('errorMessage');
errorEl.textContent = message;
errorEl.classList.add('show');
setTimeout(() => this.hideError(), 5000);
}hideError() {
document.getElementById('errorMessage').classList.remove('show');
}showToast(message, type = 'info') {
const toast = document.getElementById('toast');
toast.textContent = message;
toast.className = `toast show ${type}`;
// Set color based on type
if (type === 'success') {
toast.style.background = 'var(--primary-gradient)';
} else if (type === 'warning') {
toast.style.background = 'var(--warning-color)';
} else if (type === 'error') {
toast.style.background = 'var(--error-color)';
}
setTimeout(() => {
toast.classList.remove('show');
}, 3000);
}get lastResults() {
return this._lastResults;
}set lastResults(value) {
this._lastResults = value;
// Save to local storage
this.savedCalculations.push({ ...value, timestamp: new Date().toISOString() });
if (this.savedCalculations.length > 10) {
this.savedCalculations = this.savedCalculations.slice(-10);
}
localStorage.setItem('fvaCalculations', JSON.stringify(this.savedCalculations));
}displayResults(results) {
this.lastResults = results;
// Display logic handled by animateValue
}
}// Initialize calculator when DOM is ready
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', () => {
window.fvaCalculator = new FVACalculator();
});
} else {
window.fvaCalculator = new FVACalculator();
}// Performance monitoring
if ('PerformanceObserver' in window) {
const perfObserver = new PerformanceObserver((list) => {
for (const entry of list.getEntries()) {
if (entry.entryType === 'largest-contentful-paint') {
console.log(`LCP: ${entry.startTime}`);
}
if (entry.entryType === 'first-input-delay') {
console.log(`FID: ${entry.processingStart - entry.startTime}`);
}
if (entry.entryType === 'cumulative-layout-shift') {
console.log(`CLS: ${entry.value}`);
}
}
});
perfObserver.observe({ entryTypes: ['largest-contentful-paint', 'first-input-delay', 'cumulative-layout-shift'] });
}// Service worker registration for caching
if ('serviceWorker' in navigator) {
navigator.serviceWorker.register('data:text/javascript,' + encodeURIComponent(`
self.addEventListener('install', e => e.waitUntil(self.skipWaiting()));
self.addEventListener('activate', e => e.waitUntil(self.clients.claim()));
self.addEventListener('fetch', e => {
e.respondWith(
caches.match(e.request).then(response => response || fetch(e.request))
);
});
`)).catch(() => {
// Silent fail - not critical
});
}