-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
24 lines (21 loc) · 854 Bytes
/
index.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
const loanInput = document.getElementById("amount");
const interestInput = document.getElementById("interest");
const monthInput = document.getElementById("month");
const resultEMI = document.getElementById("emi");
const emiCalculator = () => {
const LoanAmount = parseFloat(loanInput.value);
const annualInterest = parseFloat(interestInput.value);
const monthsToPay = parseInt(monthInput.value);
const monthlyInterest = (annualInterest * 0.01) / 12;
const EMI = (
(LoanAmount *
monthlyInterest *
Math.pow(1 + monthlyInterest, monthsToPay)) /
(Math.pow(1 + monthlyInterest, monthsToPay) - 1)
).toFixed(2);
resultEMI.innerText = EMI;
};
loanInput.addEventListener("change", emiCalculator);
interestInput.addEventListener("change", emiCalculator);
monthInput.addEventListener("change", emiCalculator);
emiCalculator();