The summit is in sight
Final day! You'll add the two features that make the tracker feel real: a streak count for each habit, and saving so habits survive a refresh. Then — celebration.
Counting a streak
A streak is how many days in a row, ending today, a habit was done. Walk backwards one day at a time until a day is missing:
function streak(days, from) {
let count = 0;
const d = new Date(from + "T12:00:00Z");
while (days.includes(d.toISOString().slice(0, 10))) {
count++;
d.setUTCDate(d.getUTCDate() - 1);
}
return count;
}
console.log(streak(["2026-10-06", "2026-10-07", "2026-10-08"], "2026-10-08"));
console.log(streak(["2026-10-06", "2026-10-08"], "2026-10-08"));