Compound interest is the reason small, regular savings grow into big money over time — and a calculator app is the best way to see it for yourself. In this tutorial, we will build a simple compound interest calculator with HTML, CSS, and JavaScript. No frameworks, no build tools.
The idea is simple. The user enters a starting amount, a monthly contribution, an annual interest rate, and a number of years. The app calculates the future value using the compound interest formula and shows how much of the total is contributions and how much is interest earned.
<input id="principal" type="number" placeholder="Starting amount (₹)">
<input id="monthly" type="number" placeholder="Monthly contribution (₹)">
<input id="rate" type="number" placeholder="Annual interest rate (%)">
<input id="years" type="number" placeholder="Years">
<button onclick="calculate()">Calculate</button>
<p id="result"></p>
The formula for the future value with monthly contributions is:
function calculate() {
const P = Number(document.getElementById('principal').value);
const monthly = Number(document.getElementById('monthly').value);
const r = Number(document.getElementById('rate').value) / 100 / 12;
const n = Number(document.getElementById('years').value) * 12;
// Compound interest on the starting amount
const futurePrincipal = P * Math.pow(1 + r, n);
// Future value of the monthly contributions
const futureMonthly = monthly * ((Math.pow(1 + r, n) - 1) / r);
const total = futurePrincipal + futureMonthly;
const invested = P + monthly * n;
document.getElementById('result').textContent =
`In ${n / 12} years you will have ₹${total.toFixed(0)}. ` +
`You invested ₹${invested.toFixed(0)} and earned ₹${(total - invested).toFixed(0)} in interest.`;
}
Why build this app? First, you practise reading inputs, doing math, and updating the page — the core of every interactive app. Second, you get a tool that teaches a real money skill: the interest earned is often bigger than people expect, which is why starting early matters so much. If you want to understand the mindset behind growing money, not just the math, this Hindi guide to Rich Dad Poor Dad explains how the rich think about money and assets — it pairs well with what this calculator shows you in numbers.
A few ideas to extend it: draw the growth as a bar chart, let the user compare two interest rates side by side, or add a slider for the years so the numbers update live. Each of those is a small feature and a good next lesson.
Try it with real numbers: ₹10,000 to start, ₹2,000 a month, 12% a year, for 20 years. The result surprises almost everyone the first time they see it — and that surprise is the point of the app.
Top comments (0)