forked from AvirupaChakraborty/Html-and-css3-handson
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFixed And Reducing Interest Loan Estimator(js)
60 lines (49 loc) · 2.35 KB
/
Fixed And Reducing Interest Loan Estimator(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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
const _principalAmount = document.getElementById("principalAmount");
const _interestRateYear = document.getElementById("interestRate");
const _tenureMonth = document.getElementById("tenure");
function getEmiReducing(P, N, R) {
return (P * R * (Math.pow((1 + R), N) / (Math.pow((1 + R), N) - 1)));
}
function EstimateReducingInterestLoan() {
calculateEMI();
totalPayment();
totalInterest();
EstimateFixedInterestLoan();
}
function EstimateFixedInterestLoan() {
const principalAmount = Number(_principalAmount.value);
const interestRateYear = Number(_interestRateYear.value);
const tenureMonth = Number(_tenureMonth.value);
const totalInterestFixed = principalAmount * interestRateYear * tenureMonth / 1200;
const totalPaymentFixed = principalAmount + totalInterestFixed;
const emiFixed = totalPaymentFixed / tenureMonth;
document.getElementById("tInterestFixed").innerHTML = Number(totalInterestFixed).toFixed(2).toString();
document.getElementById("tPaymentFixed").innerHTML = Number(totalPaymentFixed).toFixed(2).toString();
document.getElementById("EMIFixed").innerHTML = Number(emiFixed).toFixed(2).toString();
}
function reducingLoan() {
const principalAmount = Number(_principalAmount.value);
const interestRateYear = Number(_interestRateYear.value);
const interestRateMonth = Number(interestRateYear / 1200);
const tenureMonth = Number(_tenureMonth.value);
const emiReducing = getEmiReducing(principalAmount, tenureMonth, interestRateMonth);
const totalPaymentReducing = tenureMonth * emiReducing;
const totalInterestReducing = totalPaymentReducing - principalAmount;
return {
emiReducing: emiReducing,
totalPaymentReducing: totalPaymentReducing,
totalInterestReducing: totalInterestReducing
};
}
function calculateEMI() {
const emiReducing = reducingLoan().emiReducing;
document.getElementById("EMI").innerHTML = Number(emiReducing).toFixed(2).toString();
}
function totalPayment() {
const totalPaymentReducing = reducingLoan().totalPaymentReducing;
document.getElementById("tPayment").innerHTML = Number(totalPaymentReducing).toFixed(2).toString();
}
function totalInterest() {
const totalInterestReducing = reducingLoan().totalInterestReducing;
document.getElementById("tInterest").innerText = Number(totalInterestReducing).toFixed(2).toString();
}