forked from ayush-that/FinVeda
-
Notifications
You must be signed in to change notification settings - Fork 0
/
RDCalculator.js
33 lines (27 loc) · 1.58 KB
/
RDCalculator.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
document.addEventListener("DOMContentLoaded", function() {
document.getElementById("calculate-Btn3").addEventListener("click", function() {
const monthlyInstallment = parseFloat(document.getElementById("monthly-installment").value);
const annualInterestRate = parseFloat(document.getElementById("rate1").value);
const timePeriodMonths = parseFloat(document.getElementById("months1").value);
if (isNaN(monthlyInstallment) || isNaN(annualInterestRate) || isNaN(timePeriodMonths)) {
alert("Please fill in all fields");
return;
}
const monthlyInterestRate = annualInterestRate / 12 / 100;
let maturityAmount = 0;
for (let i = 0; i < timePeriodMonths; i ) {
maturityAmount = monthlyInstallment * Math.pow((1 monthlyInterestRate), (timePeriodMonths - i));
}
const totalInvestAmount = monthlyInstallment * timePeriodMonths;
const interestEarned = maturityAmount - totalInvestAmount;
document.getElementById("interestEarned1").innerText = `₹${interestEarned.toFixed(2)}`;
document.getElementById("maturityAmount1").innerText = `₹${maturityAmount.toFixed(2)}`;
});
document.getElementById("clearBtn2").addEventListener("click", function() {
document.getElementById("monthly-installment").value = '';
document.getElementById("rate1").value = '';
document.getElementById("months1").value = '';
document.getElementById("interestEarned1").innerText = '';
document.getElementById("maturityAmount1").innerText = '';
});
});