Project Introduction
The Expense Tracker is a JavaScript project that allows users to record their income and expenses, calculate the current balance, and manage transaction records.
Learn how to build a JavaScript Expense Tracker with income, expenses, balance and Local Storage.
In this project, you will learn how to create an Expense Tracker using HTML, CSS and JavaScript. You will learn arrays, objects, DOM manipulation, localStorage and calculations.
The Expense Tracker is a JavaScript project that allows users to record their income and expenses, calculate the current balance, and manage transaction records.
Create the basic page structure with a title, balance section, transaction form, amount input, transaction type and transaction list.
The form collects important information such as transaction description, amount and whether the transaction is income or expense.
Use document.getElementById() to select form elements and read the values entered by the user.
Store transaction objects inside a JavaScript array. Each transaction can contain an id, description, amount and type.
Create a function that validates the input and adds a new transaction object to the transaction array.
Use the transaction type to determine whether an amount should be added to income or counted as an expense.
Calculate total income and total expenses, then calculate the balance using the formula: Balance = Income - Expenses.
Use JavaScript DOM methods to dynamically create transaction items and display them on the webpage.
Give every transaction a unique id and create a delete function that removes the selected transaction from the array.
Use localStorage to save transactions in the browser so that the user's records remain available after refreshing the page.
When the page loads, retrieve saved transaction data from localStorage and convert the JSON data back into a JavaScript array.
Whenever a transaction is added or deleted, recalculate income, expenses and balance and update the summary section.
Create a function that clears all transactions and removes the saved data from localStorage.
The complete project flow is: Enter transaction → Validate input → Save transaction → Update array → Calculate income and expense → Update balance → Display transactions → Save to localStorage.
After understanding each step, open the complete Expense Tracker project and test different income and expense transactions.
const income = transactions
.filter(item => item.type === "income")
.reduce((sum, item) => sum + item.amount, 0);
const expenses = transactions
.filter(item => item.type === "expense")
.reduce((sum, item) => sum + item.amount, 0);
const balance = income - expenses;
console.log("Income:", income);
console.log("Expenses:", expenses);
console.log("Balance:", balance);
localStorage.setItem(
"aifa_expenses",
JSON.stringify(transactions)
);
const savedData =
localStorage.getItem("aifa_expenses");
const transactions =
savedData ? JSON.parse(savedData) : [];
Enter Transaction → Validate Input → Save Transaction → Update Array → Calculate Income & Expenses → Calculate Balance → Display Transactions → Save to Local Storage