DEV Community

Arhan Khan
Arhan Khan

Posted on

Build a Morning Routine Planner App with JavaScript

A morning routine planner is a simple app with a real payoff: you list the habits you want each morning, check them off one by one, and the app shows your streak. It teaches you localStorage, rendering lists from data, and the streak logic that powers apps like Duolingo.

The data model is an array of habits, each with a name, a duration, and whether it is done today:

const defaultHabits = [
  { id: 1, name: "Drink a glass of water", minutes: 2, done: false },
  { id: 2, name: "Stretch for 5 minutes", minutes: 5, done: false },
  { id: 3, name: "Read 10 pages", minutes: 15, done: false },
  { id: 4, name: "Plan the day", minutes: 5, done: false },
];
Enter fullscreen mode Exit fullscreen mode

Render the list from the data, and let clicking a habit toggle it:

let habits = loadHabits();

function render() {
  const list = document.getElementById("habitList");
  list.innerHTML = "";
  habits.forEach((habit) => {
    const li = document.createElement("li");
    li.textContent = `${habit.name} — ${habit.minutes} min`;
    if (habit.done) li.classList.add("done");
    li.addEventListener("click", () => {
      habit.done = !habit.done;
      saveHabits();
      render();
    });
    list.appendChild(li);
  });
  updateProgress();
}

function updateProgress() {
  const done = habits.filter((h) => h.done).length;
  document.getElementById("progress").textContent =
    `${done} of ${habits.length} habits done`;
}
Enter fullscreen mode Exit fullscreen mode

Persistence is the key feature. Save to localStorage on every change, and reset all habits to done: false at midnight — compare the stored date with today when the app loads:

function saveHabits() {
  localStorage.setItem("morningHabits", JSON.stringify(habits));
  localStorage.setItem("habitDate", new Date().toDateString());
}

function loadHabits() {
  const savedDate = localStorage.getItem("habitDate");
  const today = new Date().toDateString();
  if (savedDate !== today) {
    return defaultHabits.map((h) => ({ ...h, done: false }));
  }
  return JSON.parse(localStorage.getItem("morningHabits")) || defaultHabits;
}
Enter fullscreen mode Exit fullscreen mode

The streak is the motivating part. Store a streak number and a lastCompletedDate. When every habit is done, check whether yesterday was also a complete day — if yes, add one to the streak, if not, reset it to one. Show the streak big at the top of the app. Watching a number grow is a surprisingly strong reason to open the app tomorrow.

The idea behind the app comes straight from habit science: make the routine visible, make starting it easy, and never break the chain twice. Atomic Habits explains why this works — small habits, repeated daily, compound into real change, and tracking the streak is what keeps the loop going.

Extensions to try next: drag to reorder habits, a timer mode that walks you through each habit in order, and a weekly summary chart drawn with plain canvas. Each feature is small on its own, and together they turn a toy into a tool you actually use.

Top comments (0)