DEV Community

Arhan Khan
Arhan Khan

Posted on

Build a Loan EMI Calculator App with JavaScript

A loan EMI calculator is one of the most useful small apps you can build. It takes a loan amount, an interest rate, and a tenure, and tells you the monthly payment — the same number banks show you before you sign anything. Building it teaches you forms, math in JavaScript, and updating the page live.

How does it work? The EMI formula is simple: EMI = P × r × (1 + r)^n / ((1 + r)^n − 1), where P is the loan amount, r is the monthly interest rate, and n is the number of months. You read the three inputs, run the formula, and show the result.

<h2>Loan EMI Calculator</h2>
<label>Loan amount (₹) <input type="number" id="amount" value="500000"></label>
<label>Interest rate (% per year) <input type="number" id="rate" value="9.5"></label>
<label>Tenure (years) <input type="number" id="years" value="5"></label>
<button id="calc">Calculate EMI</button>
<p id="result"></p>
Enter fullscreen mode Exit fullscreen mode
document.getElementById('calc').addEventListener('click', () => {
  const P = Number(document.getElementById('amount').value);
  const annualRate = Number(document.getElementById('rate').value);
  const years = Number(document.getElementById('years').value);

  const r = annualRate / 12 / 100; // monthly rate
  const n = years * 12; // months

  const emi = (P * r * Math.pow(1 + r, n)) / (Math.pow(1 + r, n) - 1);
  const totalPaid = emi * n;
  const totalInterest = totalPaid - P;

  document.getElementById('result').innerHTML =
    `Monthly EMI: ₹${emi.toFixed(2)}<br>` +
    `Total interest: ₹${totalInterest.toFixed(2)}<br>` +
    `Total payment: ₹${totalPaid.toFixed(2)}`;
});
Enter fullscreen mode Exit fullscreen mode

This app is great for beginners because the whole logic is one formula and one event listener. You also learn a real-world lesson while building it: a small change in the interest rate or tenure changes the total interest by thousands of rupees, which is why understanding loans matters before borrowing. If you want to go deeper into how money and loans actually work, the best personal finance books for Indians explain these ideas in simple language, and they are worth reading before taking any big loan.

When should you build it? Whenever you want a project that is genuinely useful — share it with a friend who is planning a home or car loan, and it stops being a toy project. You can extend it later with a chart of the payment schedule, or a comparison of two loan offers side by side.

The limits are worth knowing. This is a simple calculator, not financial advice — real loans have processing fees, floating rates, and prepayment rules that change the numbers. Always check the bank's own schedule before deciding.

Start today: build the calculator above, try a ₹5,00,000 loan at 9.5% for 5 years, then change the tenure to 7 years and watch the total interest jump. That jump is the lesson the app teaches.

Top comments (0)