function calculate() { const initialInvestment = parseFloat(document.getElementById('initialInvestment').value); const years = parseInt(document.getElementById('years').value); const returnRate = parseFloat(document.getElementById('returnRate').value) / 100; const additionalContribution = parseFloat(document.getElementById('additionalContribution').value); const contributionFrequency = parseInt(document.getElementById('contributionFrequency').value); let totalValue = initialInvestment; const periods = years * contributionFrequency; const ratePerPeriod = returnRate / contributionFrequency; for (let i = 1; i <= periods; i++) { totalValue = (totalValue + additionalContribution) * (1 + ratePerPeriod); } document.getElementById('totalValue').textContent = totalValue.toFixed(2); }