Darekdari / JavaScript Projects

Build a Personal Finance Tracker in JavaScript

Creating your own personal finance tracker javascript project is a practical way to take control of your money and sharpen your coding skills. Follow the steps below, try the live demo, and copy the full source code.

HTMLCSSVanilla JavaScriptBeginner friendly
01 / Getting started

Getting Started with a Personal Finance Tracker JavaScript Project

This tutorial builds a small app that records income and expenses, saves them in your browser, and shows a running balance. We start with the basics and finish with a tool you can keep extending.

You should be comfortable with basic HTML, CSS and JavaScript concepts such as variables, functions and the DOM. We won’t cover the absolute fundamentals, but each step is explained as we go.

What the finished tracker does

  • Adds income and expenses with a description, an amount and a category.
  • Validates input so empty or negative amounts never reach your totals.
  • Lists every transaction with a date and a delete button.
  • Saves data with localStorage, so your entries survive a page refresh.
02 / Structure

HTML Structure

The layout has three parts: a summary, a form with description, amount and category fields, and a list that will hold the transactions. Using real label elements and a form makes the page more accessible and lets users press Enter to submit.

index.html
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>Personal Finance Tracker</title>
  <link rel="stylesheet" href="style.css">
</head>
<body>
  <h1>Personal Finance Tracker</h1>

  <div id="summary">
    Income: $<span id="totalIncome">0.00</span>
    Expenses: $<span id="totalExpenses">0.00</span>
    Balance: $<span id="balance">0.00</span>
  </div>

  <form id="form">
    <input id="label" placeholder="Description" required>
    <input id="amount" type="number" step="0.01" min="0.01" placeholder="Amount" required>
    <select id="category">
      <option>Salary</option><option>Rent</option>
      <option>Groceries</option><option>Entertainment</option>
    </select>
    <button type="button" data-type="income">Add Income</button>
    <button type="button" data-type="expense">Add Expense</button>
  </form>
  <p id="msg"></p>
  <ul id="list"></ul>

  <script src="app.js"></script>
</body>
</html>
03 / Logic

JavaScript Logic

Instead of keeping two running totals, we store every transaction in an array and calculate the totals from it. That one change gives us a transaction list, deletion and persistence almost for free.

The original version used parseFloat without checking the result, so an empty field produced NaN and broke the totals. The version below validates the amount first.
app.js
const KEY = 'finance-tracker';
const $ = (id) => document.getElementById(id);
let items = [];

try { items = JSON.parse(localStorage.getItem(KEY)) || []; } catch (e) {}

function save() {
  try { localStorage.setItem(KEY, JSON.stringify(items)); } catch (e) {}
  render();
}

function add(type) {
  const amount = parseFloat($('amount').value);
  if (!Number.isFinite(amount) || amount <= 0) {
    $('msg').textContent = 'Enter an amount greater than 0.';
    return;
  }
  items.push({
    id: Date.now(),
    type,
    amount,
    label: $('label').value.trim() || 'Untitled',
    category: $('category').value,
    date: new Date().toISOString().slice(0, 10)
  });
  $('form').reset();
  $('msg').textContent = '';
  save();
}

function remove(id) {
  items = items.filter((i) => i.id !== id);
  save();
}

function render() {
  let income = 0, expenses = 0;
  $('list').textContent = '';
  items.slice().reverse().forEach((i) => {
    if (i.type === 'income') income += i.amount; else expenses += i.amount;
    const li = document.createElement('li');
    li.textContent = i.date + '  ' + i.label + '  ' +
      (i.type === 'income' ? '+' : '-') + '$' + i.amount.toFixed(2);
    const del = document.createElement('button');
    del.textContent = 'Delete';
    del.onclick = () => remove(i.id);
    li.appendChild(del);
    $('list').appendChild(li);
  });
  $('totalIncome').textContent = income.toFixed(2);
  $('totalExpenses').textContent = expenses.toFixed(2);
  $('balance').textContent = (income - expenses).toFixed(2);
}

document.querySelectorAll('[data-type]').forEach((b) =>
  b.addEventListener('click', () => add(b.dataset.type)));
render();

Why this approach works

Totals are always derived from the array, so they can never drift out of sync with the list. Building list items with textContent instead of innerHTML also keeps user-typed descriptions from injecting HTML into the page.

04 / Styling

Styling with CSS

Add some basic CSS to make the tracker readable on any screen. Customize the colors and spacing to match your own style.

style.css
body {
  font-family: Arial, sans-serif;
  max-width: 640px;
  margin: 20px auto;
  padding: 0 16px;
}
h1 { text-align: center; }
#summary {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  background: #f0f0f0;
  padding: 12px;
  border: 1px solid #ccc;
  border-radius: 8px;
}
#form { display: grid; gap: 10px; margin: 20px 0; }
input, select, button { padding: 10px; font-size: 1rem; }
li { display: flex; justify-content: space-between; padding: 8px 0; }
@media (min-width: 600px) {
  #form { grid-template-columns: 2fr 1fr 1fr; }
}
05 / Try it

Live Demo: Your Finance Tracker in Action

This working demo follows the same logic as the code above. Entries are saved only in your own browser with localStorage, and nothing is sent anywhere.

Income$0.00
Expenses$0.00
Balance$0.00
    06 / Level up

    Enhancing Your Personal Finance Tracker

    The code above, now with validation, a transaction list and saved data, is a solid foundation. Here are the next features worth building:

    • Data persistence: localStorage is already included. For multiple devices, add a backend database.
    • Categories: group spending under labels like Rent, Groceries and Entertainment, then total each category.
    • Date tracking: let users choose the transaction date, filter by month and monitor their financial history.
    • Charting: visualize spending with a library such as Chart.js for a more intuitive overview.
    • Authentication: add user accounts if the data lives on a server, so financial information stays private.
    • Notifications: alert users when they reach a savings goal or exceed a budget limit.
    • Budget planner: set monthly limits per category and show visual cues when one is close to being exceeded.

    Treat this as a dynamic project: customize and expand it to fit your own tracking needs.

    07 / Practice

    JavaScript Exercises to Practice with This Project

    Building a tracker is one of the best javascript exercises for beginners because it touches variables, functions, arrays, events and the DOM in a single app. If you want javascript exercises and solutions to compare against, try rebuilding each feature from scratch before you check the code above.

    Variables and functions

    Start with javascript variables exercises: store the totals in variables, change them, and watch how the balance updates. Then move to javascript function exercises by splitting the logic into small, reusable functions like add, remove and render.

    Challenges to try next

    These javascript practice exercises with solutions are easy to verify because the demo above shows the expected result. Treat them as javascript tasks for practice and, if you like short drills, as js exercises you can finish in one sitting:

    1. Add an “Edit” button that changes an existing transaction.
    2. Show a subtotal for each category.
    3. Filter the list by income, expenses or month.
    4. Export the transactions as a CSV file.

    For more javascript exercises, browse our JavaScript projects.

    08 / FAQ

    Frequently Asked Questions

    What can you build with JavaScript?

    JavaScript powers interactive websites, games, dashboards, browser tools and, with Node.js, servers. A finance tracker is a great first project because it combines forms, data storage and calculations.

    How do I start a JavaScript project?

    Pick a small problem, create an HTML file, link a JavaScript file, and build one feature at a time. This tracker is a good template: structure first, then logic, then styling.

    Is localStorage safe for financial data?

    It is fine for a learning project, but it is not encrypted and anyone with access to the browser can read it. Never store passwords or bank details there; real financial apps need a secure backend and authentication.

    Is JavaScript hard for beginners?

    It has a gentle start, since you can see results in the browser immediately. Concepts like asynchronous code take longer, so practice with small projects like this one.

    Conclusion

    Take Your Finance Tracker Further

    In summary, creating a personal finance tracker with JavaScript gives you a useful tool and real practice with the DOM, arrays and browser storage. By following the steps and adding the features above, you can tailor the project to your needs and build greater financial control and understanding through coding.

    Learn more

    Scroll to Top