A budget calculator is a small app with a real payoff: type in your income and expenses, and it shows where your money goes. It teaches you forms, live calculations, and updating the page without reloading — and you end up with a tool you can actually use. If budgeting feels confusing, the best personal finance books for Indians explain the ideas behind the numbers this app calculates.
What you are building
Three inputs: monthly income, and a list of expenses with a name and an amount. The app shows total expenses, money left over, and a simple breakdown — how much goes to needs, wants, and savings. Adding or removing an expense updates everything instantly.
The HTML structure
<h2>Monthly Budget Calculator</h2>
<label>Monthly income: <input type="number" id="income" value="50000"></label>
<h3>Add an expense</h3>
<input type="text" id="expense-name" placeholder="Rent">
<input type="number" id="expense-amount" placeholder="15000">
<button id="add-expense">Add</button>
<ul id="expense-list"></ul>
<p>Total expenses: <span id="total">0</span></p>
<p>Money left: <span id="remaining">0</span></p>
The calculation logic
Keep expenses in an array and re-render on every change. One render function keeps the page and the data in sync:
const expenses = [];
const incomeInput = document.getElementById("income");
function render() {
const income = Number(incomeInput.value) || 0;
const total = expenses.reduce((sum, item) => sum + item.amount, 0);
const remaining = income - total;
document.getElementById("total").textContent = total;
document.getElementById("remaining").textContent = remaining;
const list = document.getElementById("expense-list");
list.innerHTML = "";
expenses.forEach((item, index) => {
const li = document.createElement("li");
li.textContent = item.name + ": " + item.amount + " ";
const removeBtn = document.createElement("button");
removeBtn.textContent = "Remove";
removeBtn.onclick = () => {
expenses.splice(index, 1);
render();
};
li.appendChild(removeBtn);
list.appendChild(li);
});
}
document.getElementById("add-expense").addEventListener("click", () => {
const name = document.getElementById("expense-name").value.trim();
const amount = Number(document.getElementById("expense-amount").value);
if (!name || !amount) return;
expenses.push({ name, amount });
render();
});
incomeInput.addEventListener("input", render);
render();
Adding the 50/30/20 rule
A classic budgeting rule splits income into 50% needs, 30% wants, and 20% savings. Add a small section that shows the target amount for each, so the user can compare their real spending with the guideline:
function showRule(income) {
return {
needs: income * 0.5,
wants: income * 0.3,
savings: income * 0.2,
};
}
What to add next
Save the expenses in localStorage so the budget survives a page reload, add categories to each expense, or draw a simple bar chart of the breakdown with a canvas. Each feature is a small step from the code above.
Top comments (0)