DEV Community

Arhan Khan
Arhan Khan

Posted on

Build a Daily Affirmations App with JavaScript

A daily affirmations app is a small, feel-good beginner project with a surprising amount of real JavaScript inside. The user opens it each morning, gets a fresh affirmation, and can save favourites, set a daily reminder time, and share the day's line. You will practice arrays, random selection, dates, localStorage, and the Web Share API — and you will end up with an app people actually open every day.

The core idea is a curated list of affirmations grouped by theme — confidence, calm, focus, and gratitude. Each morning the app picks one it has not shown recently, so the user never sees the same line twice in a week. That single rule turns a random picker into something that feels thoughtful.

const affirmations = [
  { text: 'I can handle whatever today brings.', theme: 'confidence' },
  { text: 'I focus on one thing at a time.', theme: 'focus' },
  { text: 'I am grateful for small progress.', theme: 'gratitude' },
  { text: 'I breathe in calm and breathe out tension.', theme: 'calm' },
]

function todaysAffirmation(list, seenIds) {
  const fresh = list.filter((_, i) => !seenIds.includes(i))
  const pool = fresh.length ? fresh : list
  const pick = pool[Math.floor(Math.random() * pool.length)]
  return pick
}

function saveFavourite(affirmation) {
  const saved = JSON.parse(localStorage.getItem('favourites') || '[]')
  saved.push(affirmation.text)
  localStorage.setItem('favourites', JSON.stringify(saved))
}
Enter fullscreen mode Exit fullscreen mode

Build the interface with a large, readable affirmation card, a theme filter, a "new one" button, and a favourites list that persists in localStorage. Add a streak counter that tracks how many days in a row the user opened the app, and a share button that uses the Web Share API when it is available. If the theme resonates with you, the best self-help books in Hindi are a natural next step — they go much deeper into the same ideas of mindset and daily habits.

This project teaches you to work with dates, to avoid repeats with a simple "seen" list, and to persist user data without a backend. Once the basic version works, add a morning notification with the Notification API, a dark mode toggle, or a weekly summary of the themes the user picked most.

The limits are honest ones. Affirmations are a mindset tool, not a substitute for professional help — say so in the app, and keep the copy encouraging without making medical claims. Keep the design calm and the text large enough to read at a glance.

Ship it this weekend: one list, one picker, one card. It is a small project with a warm payoff — the kind of thing that makes a portfolio feel human.

Top comments (0)