Sikau

JavaScript · Day 60 · about 40 min

Capstone: finish

Polish, celebrate, and what's next.

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

The rest of this lesson

  • Polish that mattersexplain
  • Streak countpredict
  • Start-up sequenceorder
  • Streakswrite code
  • Save the habitschallenge
  • What's next?explain
  • Badge quizquiz
  • Capstone complete! 🎉recap

Continue this lesson free — run real code in your browser

Continue with Google

See all 68 lessons of JavaScript