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M,SAAS,oBAAoB;gBAEnC,IAAI,eAAe;gBACnB,IAAI,QAAQ,GAAG;oBACb,gBAAgB,MAAM,QAAQ,KAAM,CAAA,UAAU,IAAI,UAAU,QAAO;oBACnE,IAAI,SAAS,GACX,gBAAgB;gBAEpB;gBACA,IAAI,SAAS,GACX,gBAAgB,OAAO,QAAQ,KAAM,CAAA,WAAW,IAAI,WAAW,SAAQ;gBAGzE,mBAAmB,WAAW,GAAG;YACnC;;IAEJ;AACF","sources":["src/ts/savings/savingsCalculator.ts"],"sourcesContent":["document.addEventListener('DOMContentLoaded', () => {\n function calculateTotalMonthsNeeded(\n savingAmount: number,\n savedAmount: number,\n monthlySaving: number,\n interestRate: number,\n ): number {\n if (interestRate <= 0 || monthlySaving <= 0) {\n return -1; // Return -1 for invalid inputs\n }\n\n const remainingAmount = savingAmount - savedAmount;\n\n if (remainingAmount <= 0) {\n return 0; // If the goal is already achieved, return 0 months needed\n }\n\n const monthlyInterestRate = interestRate / 100 / 12; // Convert annual interest rate to monthly\n\n // Using the formula for the future value of an annuity with compound interest\n // FV = P * ((1 + r)^n - 1) / r\n // where FV is the future value, P is the periodic payment, r is the interest rate per period,\n // and n is the total number of periods\n const n = Math.log(1 + (remainingAmount * monthlyInterestRate) / monthlySaving) / Math.log(1 + monthlyInterestRate);\n\n // Round up to the next whole month\n const totalMonthsNeeded = Math.ceil(n);\n return totalMonthsNeeded;\n }\n\n const savingAmountInput = document.getElementById('saving-amount') as HTMLInputElement;\n const savedAmountInput = document.getElementById('saved-amount') as HTMLInputElement;\n const monthlySavingInput = document.getElementById('saving-per-month') as HTMLInputElement;\n const interestRateInput = document.getElementById('interest') as HTMLInputElement;\n const totalMonthsElement = document.querySelector('.savings__calc__result-card h2');\n\n savingAmountInput.addEventListener('input', updateResult);\n savedAmountInput.addEventListener('input', updateResult);\n monthlySavingInput.addEventListener('input', updateResult);\n interestRateInput.addEventListener('input', updateResult);\n\n function updateResult() {\n const savingAmount = parseFloat(savingAmountInput.value) || 0;\n const savedAmount = parseFloat(savedAmountInput.value) || 0;\n const monthlySaving = parseFloat(monthlySavingInput.value) || 0;\n const interestRate = parseFloat(interestRateInput.value) || 0;\n\n const totalMonthsNeeded = calculateTotalMonthsNeeded(savingAmount, savedAmount, monthlySaving, interestRate);\n\n if (totalMonthsElement) {\n if (totalMonthsNeeded === -1) {\n totalMonthsElement.textContent = '';\n } else {\n const years = Math.floor(totalMonthsNeeded / 12);\n const months = totalMonthsNeeded % 12;\n\n let resultString = '';\n if (years > 0) {\n resultString += years.toString() + (years === 1 ? ' year' : ' years');\n if (months > 0) {\n resultString += ' and ';\n }\n }\n if (months > 0) {\n resultString += months.toString() + (months === 1 ? ' month' : ' months');\n }\n\n totalMonthsElement.textContent = resultString;\n }\n }\n }\n});\n"],"names":[],"version":3,"file":"savings-calculator.052c0827.js.map"}