Changed around line 1
+ document.getElementById('calculator-form').addEventListener('submit', function(event) {
+ event.preventDefault();
+
+ const initialInvestment = parseFloat(document.getElementById('initialInvestment').value);
+ const annualDividendYield = parseFloat(document.getElementById('annualDividendYield').value) / 100;
+ const dripPercentage = parseFloat(document.getElementById('dripPercentage').value) / 100;
+ const years = parseInt(document.getElementById('years').value);
+
+ let finalAmount = initialInvestment;
+
+ for (let i = 0; i < years; i++) {
+ const dividends = finalAmount * annualDividendYield;
+ const reinvestedDividends = dividends * dripPercentage;
+ finalAmount += reinvestedDividends;
+ }
+
+ document.getElementById('finalAmount').textContent = `$${finalAmount.toFixed(2)}`;
+ document.getElementById('result').classList.remove('hidden');
+ });