Skip to content

Commit 0e8b1a5

Browse files
Update index.html
1 parent 722451c commit 0e8b1a5

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

Loan Calculator/index.html

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,19 @@ <h3>Loan Calculator</h3>
1919
<p>Months to Pay:
2020
<input type="number" value="1" id="months" min="0" onchange="calculateLoan()"> </p>
2121
<h2 id="payment"></h2> </div>
22-
<script src="script.js"></script>
22+
<script src="script.js">
23+
function calculateLoan() {
24+
const amount = document.querySelector("#amount").value;
25+
const interestRate = document.querySelector("#interest").value;
26+
const months = document.querySelector("#months").value;
27+
const monthlyRate = (interestRate) / (12 * 100);
28+
const onePlusR = Math.pow(1 + monthlyRate, months);
29+
const den = onePlusR - 1;
30+
const emi = (amount * monthlyRate * (onePlusR / den)).toFixed(2);
31+
const totalPay = (emi * months).toFixed(2);
32+
document.querySelector("#payment").innerHTML = `EMI: ₹ ${emi} <br><br> Total Payment: ₹${totalPay}`
33+
}
34+
</script>
2335
</body>
2436

2537
</html>

0 commit comments

Comments
 (0)