-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathscripts.js
86 lines (74 loc) · 3.74 KB
/
scripts.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
function updateLoanAmount() {
const loanAmountSlider = document.getElementById("loanAmountSlider");
const loanAmount = loanAmountSlider.value;
document.getElementById("loanAmountDisplay").textContent = `₹${loanAmount}`;
document.getElementById("loanAmount").value = loanAmount;
}
function updateLoanAmountSlider() {
const loanAmountInput = document.getElementById("loanAmount");
const loanAmount = loanAmountInput.value;
document.getElementById("loanAmountSlider").value = loanAmount;
document.getElementById("loanAmountDisplay").textContent = `₹${loanAmount}`;
}
function updateInterestRate() {
const interestRateSlider = document.getElementById("interestRateSlider");
const interestRate = interestRateSlider.value;
document.getElementById("interestRateDisplay").textContent = `${interestRate}%`;
document.getElementById("interestRate").value = interestRate;
}
function updateInterestRateSlider() {
const interestRateInput = document.getElementById("interestRate");
const interestRate = interestRateInput.value;
document.getElementById("interestRateSlider").value = interestRate;
document.getElementById("interestRateDisplay").textContent = `${interestRate}%`;
}
function updateLoanTenureMonths() {
const loanTenureMonthsSlider = document.getElementById("loanTenureMonthsSlider");
const tenureMonths = loanTenureMonthsSlider.value;
document.getElementById("loanTenureMonthsDisplay").textContent = `${tenureMonths} Month${tenureMonths > 1 ? 's' : ''}`;
}
function updateLoanTenureYears() {
const loanTenureYearsSlider = document.getElementById("loanTenureYearsSlider");
const tenureYears = loanTenureYearsSlider.value;
document.getElementById("loanTenureYearsDisplay").textContent = `${tenureYears} Year${tenureYears > 1 ? 's' : ''}`;
}
function showTenureMonths() {
document.getElementById("tenureMonths").style.display = 'block';
document.getElementById("tenureYears").style.display = 'none';
}
function showTenureYears() {
document.getElementById("tenureMonths").style.display = 'none';
document.getElementById("tenureYears").style.display = 'block';
}
function calculateEMI() {
const loanAmount = parseFloat(document.getElementById("loanAmount").value);
const interestRate = parseFloat(document.getElementById("interestRate").value) / 12 / 100;
const tenureMonths = document.getElementById("tenureMonths").style.display === 'block' ?
parseInt(document.getElementById("loanTenureMonthsSlider").value) :
parseInt(document.getElementById("loanTenureYearsSlider").value) * 12;
const emi = loanAmount * interestRate * Math.pow(1 + interestRate, tenureMonths) / (Math.pow(1 + interestRate, tenureMonths) - 1);
const totalPayment = emi * tenureMonths;
const totalInterest = totalPayment - loanAmount;
document.getElementById("monthlyEMI").textContent = `Monthly EMI: ₹${emi.toFixed(2)}`;
document.getElementById("totalInterest").textContent = `Total Interest: ₹${totalInterest.toFixed(2)}`;
document.getElementById("totalPayment").textContent = `Total Payment (Principal + Interest): ₹${totalPayment.toFixed(2)}`;
drawEMIChart(loanAmount, totalInterest);
}
function drawEMIChart(principal, interest) {
const ctx = document.getElementById('emiChart').getContext('2d');
new Chart(ctx, {
type: 'doughnut',
data: {
labels: ['Principal Amount', 'Interest Amount'],
datasets: [{
data: [principal, interest],
backgroundColor: ['#4CAF50', '#FF5733'],
hoverBackgroundColor: ['#45a049', '#ff6f4d']
}]
},
options: {
responsive: true,
maintainAspectRatio: false
}
});
}