# JavaScript Expense Tracker with Local Storage

TechBuilt Open School — Free, self-guided technical project kit

- **Track:** Web Development
- **Level:** Beginner
- **Access:** No account, signup, payment or enrollment required
- **Format:** Guided plan and runnable starter example, not a complete solution or a live class
- **Online guide:** https://techbuiltos.online/projects/javascript-expense-tracker

## Project goal

Learn array state, numeric validation, DOM updates and offline browser persistence through one useful tool.

Track expense entries in a browser, calculate totals and progressively add safe persistence with localStorage.

## Before you begin

- Modern browser and editor
- JavaScript variables, functions and event handlers

## Local setup

1. Create index.html with a simple form and an output element.
2. Start with the JavaScript sample below inside a script tag.
3. Keep all stored data on your own browser; no backend or account is required.

## Starter example — tracker.js

The sample below is a starting point. It may require the prerequisites above. Complete the subsequent milestones to finish your own project.

```javascript
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"));
```

## Build milestones

1. Render a form with description, amount and category.
2. Validate that descriptions are non-empty and amounts are positive finite numbers.
3. Add entries to an array and update the total.
4. Persist the array to localStorage using JSON.stringify and restore it on refresh.
5. Add remove buttons and an empty-state message; use textContent rather than innerHTML for user text.

## Completion checklist

- [ ] 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 extensions

- Add filters by category and month without mutating the original array.
- Offer CSV export with safely quoted values.

## Related learning

- Individual course roadmap: https://techbuiltos.online/courses/javascript
- Individual course roadmap: https://techbuiltos.online/courses/html5

- Specialization: https://techbuiltos.online/specializations/frontend-developer
- Specialization: https://techbuiltos.online/specializations/website-developer

---

This original self-study project is independent of paid cohorts. Review any external library documentation before use. Do not commit real credentials, private client files or personal data to public repositories.
