-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
32 lines (28 loc) · 1.38 KB
/
script.js
File metadata and controls
32 lines (28 loc) · 1.38 KB
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
document.addEventListener('DOMContentLoaded',function(){
var loan_amount = document.querySelector('#loan_amount');
var rate_of_interest = document.querySelector('#rate_of_interest');
var loan_tenure = document.querySelector('#loan_tenure');
const loan_amount_input = document.querySelector('#loan_amount_input')
const rate_of_interest_input = document.querySelector('#rate_of_interest_input')
const loan_tenure_input = document.querySelector('#loan_tenure_input')
const emi_input = document.querySelector('#emi_input')
function update(){
const currLoanAmtInput = loan_amount.value;
const currRateOfInterest = rate_of_interest.value;
const currLoanTenure = loan_tenure.value;
loan_amount_input.textContent = `₹${currLoanAmtInput}`;
rate_of_interest_input.textContent = `${currRateOfInterest}%`;
loan_tenure_input.textContent = `${currLoanTenure}`
//M = P [ i(1 + i)^n ] / [ (1 + i)^n – 1 ]. i = (Annual Rate / 100) / 12. n = Loan Term in Years * 12
const i = (currRateOfInterest/100)/12;
const n = currLoanTenure*12;
const p = currLoanAmtInput;
const emi = p *( i*Math.pow((1 + i),n) ) / ( Math.pow((1 + i),n) - 1 )
emi_input.textContent = `₹${emi.toFixed(2)}`
}
loan_amount.addEventListener('input',update);
rate_of_interest.addEventListener('input',update);
loan_tenure.addEventListener('input',update);
update()
}
)