Level 3 · Interactive Web Applications Project 27 of 60 Runs in the browser
Project 27: Habit Tracking Application
A habit tracker with a 7-day grid of toggle buttons, streaks, completion rates and a daily summary, saved in localStorage.
1 · The problem
Habits stick when you can see your progress. The tracker shows the last seven days for each habit, lets you tick a day on or off, counts the current streak (which is still alive if today is not ticked yet) and the share of days done.
User stories
- As a user, I want to tick today with one click.
- As a user, I want to see how long my streak is.
- As a user, I want a missed day to reset the streak.
2 · Requirements
- Each habit has id, name and days (a sorted array of 'YYYY-MM-DD' dates).
- Show a grid of the last 7 days ending TODAY; each cell is a toggle button with aria-pressed and a label such as 'Drink water on 2026-03-10'.
- Streak: consecutive days ending today, or ending yesterday when today is not ticked yet.
- Completion rate: the percentage of the last 7 days that are ticked, rounded.
- Summary: 'n of m habits done today'.
- Add habits (no empty names, no duplicates ignoring capitals), delete habits, and save every change.
Acceptance criteria
- Drink water starts with a 4 day streak and 57%.
- Ticking Read 20 pages today gives it a 3 day streak.
- Unticking yesterday for Drink water drops its streak to 1 day.
- Adding 'walk' when 'Walk' exists shows 'You already track that habit.'
Architecture
| Layer | File | Responsibility |
|---|---|---|
| Page | index.html + style.css | Grid table, summary, add form. |
| State | habits.js | Dates, toggling, streaks, rates, adding. Your work. |
| View and events | app.js | renderGrid, summary, events, storage. Your work. |
Flow: Click a day → habits = toggleDay(habits, id, day) → save → renderGrid() + renderSummary()
Expected result

Screenshots are captured automatically from the solution by the browser test suite.
Build it: guided stages
Pick a stage, load its starter files, follow the steps, then run the app and the tests. Every stage is preserved separately, so loading one never overwrites another.
- Stage 1: The 7-day grid · Work with date strings and draw a grid of toggle buttons.
- Stage 2: Streaks and toggling · Tick days, count streaks and rates, and delete habits.
- Stage 3: Add habits and save · Add habits safely and keep everything between visits.
Troubleshooting
- Dates are one day off.
- Build dates with 'T00:00:00Z' and use the UTC methods, so your time zone does not shift them.
- The streak is 0 although yesterday was ticked.
- When today is not ticked yet, start counting from yesterday.
- A click on a ✓ does nothing after the first change.
- renderGrid replaces the buttons; keep one listener on the table and use event.target.closest('button').
Extension challenges
- Use the real date: new Date().toISOString().slice(0, 10).
- Show the longest streak ever as well as the current one.
- Let the user choose 7, 14 or 30 days.
Downloads
- Starter files
- Stage 1: The 7-day grid (starter, complete, tests)
- Stage 2: Streaks and toggling (starter, complete, tests)
- Stage 3: Add habits and save (starter, complete, tests)
- Complete solution
- Whole project folder (README, requirements, architecture, checkpoints, tests, sample data, prompts)
Browser projects open directly from index.html. Node.js unit tests: run node --test in the project folder.
AI development prompts
Context: I am building the academy's Habit Tracking Application. Task: explain why dates are stored as 'YYYY-MM-DD' strings here. Constraints: explain the idea and point to the line that matters; do not write the whole solution. Expected behaviour: I can finish the stage myself. Testing: suggest two inputs that would show whether my code is right.
Context: My Habit Tracking Application passes the visible tests. Task: check my streak function with a habit ticked only today and one ticked only yesterday. Constraints: do not rewrite my code; list issues in order of importance. Expected behaviour: I understand each issue and can fix it. Testing: give one test case per issue.
Context: I finished the Habit Tracking Application. Task: help me plan this extension: show the longest streak. Constraints: keep the logic file free of page code; existing tests must still pass. Expected behaviour: a short plan with the functions to add or change. Testing: describe the new tests I should write first.
Source
Repository folder: projects/project-27-habit-tracking-application/ · view on GitHub