Web DevelopmentBeginnerFree to access
JavaScript Expense Tracker with Local Storage
Track expense entries in a browser, calculate totals and progressively add safe persistence with localStorage.
Download free Markdown guideNo email, account or payment required · .md text format
What you will build
Learn array state, numeric validation, DOM updates and offline browser persistence through one useful tool.
Before you begin
- Modern browser and editor
- JavaScript variables, functions and event handlers
Local setup instructions
- Create index.html with a simple form and an output element.
- Start with the JavaScript sample below inside a script tag.
- Keep all stored data on your own browser; no backend or account is required.
Starter code
tracker.jsThis is a working starting example, not the finished project. Follow the setup above and complete each milestone to build your own solution.
const expenses = [
{ description: "Notebook", amount: 150 },
{ description: "Transport", amount: 220 },
];
function totalExpenses(items) {
return items.reduce((sum, item) => sum + item.amount, 0);
}
function addExpense(items, description, inputAmount) {
const amount = Number(inputAmount);
if (!description.trim() || !Number.isFinite(amount) || amount <= 0) {
throw new Error("Enter a description and a positive amount.");
}
return [...items, { description: description.trim(), amount }];
}
console.log("Total:", totalExpenses(expenses));
console.log(addExpense(expenses, "Lunch", "300"));Project build milestones
- Render a form with description, amount and category.
- Validate that descriptions are non-empty and amounts are positive finite numbers.
- Add entries to an array and update the total.
- Persist the array to localStorage using JSON.stringify and restore it on refresh.
- Add remove buttons and an empty-state message; use textContent rather than innerHTML for user text.
Completion checklist
Use these checks to self-review the finished project.
- Invalid and negative amounts are rejected.
- Totals are numeric and reflect add/remove actions.
- Refreshing the page preserves saved entries after persistence is implemented.
- Free-text descriptions are displayed using textContent.
Optional challenges
- Add filters by category and month without mutating the original array.
- Offer CSV export with safely quoted values.