DEV Community

Arhan Khan
Arhan Khan

Posted on

Build a Reading Habit Tracker App with JavaScript

Reading every day is one of the best habits you can build, and a small tracker app is a perfect first JavaScript project. In this tutorial we will build a Reading Habit Tracker: add a book, log the pages you read each day, see your streak, and watch a progress bar fill up. No framework, no database — just HTML, CSS, and JavaScript, with your data saved in localStorage so it survives a refresh.

First, the data model. We keep a list of books, and each book has a title, a total page count, and a log of daily entries. Every entry records the date and the pages read that day. From this we can compute total pages read, progress percentage, and the current streak.

// The data we store
const books = [
  { id: 1, title: "Atomic Habits", totalPages: 320, pagesRead: 0, log: [] },
];

function logPages(bookId, pages) {
  const book = books.find((b) => b.id === bookId);
  book.pagesRead += pages;
  book.log.push({ date: new Date().toDateString(), pages });
  saveBooks();
  render();
}

function getStreak(book) {
  // Count consecutive days with a log entry, ending today
  const dates = new Set(book.log.map((e) => e.date));
  let streak = 0;
  let day = new Date();
  while (dates.has(day.toDateString())) {
    streak++;
    day.setDate(day.getDate() - 1);
  }
  return streak;
}
Enter fullscreen mode Exit fullscreen mode

Next, the interface. A form adds a new book with its title and total pages. Each book gets a card showing a progress bar, the pages read, the current streak, and a small form to log today's pages. A single render() function redraws everything from the data, so the UI can never get out of sync.

function saveBooks() {
  localStorage.setItem("reading-books", JSON.stringify(books));
}

function loadBooks() {
  const saved = localStorage.getItem("reading-books");
  return saved ? JSON.parse(saved) : [];
}
Enter fullscreen mode Exit fullscreen mode

If you want to go further, add a daily goal — say 20 pages a day — and show a green check when you hit it. Add a weekly chart with a few divs sized by pages read. Add a "finished" state that celebrates when a book reaches 100%. Each of these is a small, self-contained feature, which is exactly how real apps grow.

A tracker like this is also a good reason to build a real reading habit. If you want books to read and learning resources to keep the habit going, Skill Library has a large collection of books and guides for beginners — a good place to pick your next book once you finish the current one.

This project teaches the core skills of every JavaScript app: state in plain objects, rendering from data, saving to localStorage, and handling dates. Build it in an afternoon, use it every day, and your next project will feel much easier.

Top comments (1)

Collapse
 
alexshev profile image
Alex Shev •

A habit tracker becomes trustworthy when it separates an observed completion from a user correction. I’d model each check-in as an event with its timezone and source, then derive streaks from that history rather than mutating one counter. That makes missed days, late edits, and future rule changes explainable instead of producing a mysterious number.