Changed around line 1
+ document.addEventListener('DOMContentLoaded', function() {
+ const incomeForm = document.getElementById('incomeForm');
+ const incomeList = document.getElementById('incomeList');
+ const expenseForm = document.getElementById('expenseForm');
+ const expenseList = document.getElementById('expenseList');
+ const savingsForm = document.getElementById('savingsForm');
+ const savingsList = document.getElementById('savingsList');
+ const totalIncome = document.getElementById('totalIncome');
+ const totalExpenses = document.getElementById('totalExpenses');
+ const remainingFunds = document.getElementById('remainingFunds');
+
+ let incomes = [];
+ let expenses = [];
+ let savingsGoals = [];
+
+ function updateSummary() {
+ const totalInc = incomes.reduce((sum, income) => sum + income.amount, 0);
+ const totalExp = expenses.reduce((sum, expense) => sum + expense.amount, 0);
+ const remaining = totalInc - totalExp;
+
+ totalIncome.textContent = `$${totalInc}`;
+ totalExpenses.textContent = `$${totalExp}`;
+ remainingFunds.textContent = `$${remaining}`;
+ }
+
+ incomeForm.addEventListener('submit', function(e) {
+ e.preventDefault();
+ const source = document.getElementById('incomeSource').value;
+ const amount = parseFloat(document.getElementById('incomeAmount').value);
+
+ incomes.push({ source, amount });
+ const li = document.createElement('li');
+ li.textContent = `${source}: $${amount}`;
+ incomeList.appendChild(li);
+
+ updateSummary();
+ incomeForm.reset();
+ });
+
+ expenseForm.addEventListener('submit', function(e) {
+ e.preventDefault();
+ const category = document.getElementById('expenseCategory').value;
+ const amount = parseFloat(document.getElementById('expenseAmount').value);
+
+ expenses.push({ category, amount });
+ const li = document.createElement('li');
+ li.textContent = `${category}: $${amount}`;
+ expenseList.appendChild(li);
+
+ updateSummary();
+ expenseForm.reset();
+ });
+
+ savingsForm.addEventListener('submit', function(e) {
+ e.preventDefault();
+ const goal = document.getElementById('savingsGoal').value;
+ const target = parseFloat(document.getElementById('savingsTarget').value);
+ const date = document.getElementById('savingsDate').value;
+
+ savingsGoals.push({ goal, target, date });
+ const li = document.createElement('li');
+ li.textContent = `${goal}: $${target} by ${date}`;
+ savingsList.appendChild(li);
+
+ savingsForm.reset();
+ });
+ });