Gratitude Jar

Gratitude Jar Icon

Gratitude Jar

Write one thing you’re grateful for today 💛


Add to Jar

    const gratitudeEntries = new Set(); const blockedWords = [“badword1”, “stupid”, “hate”, “idiot”, “kill”, “ugly”]; const heartEmojis = [“💖”, “💗”, “💚”, “💜”, “💙”, “❤️”]; const quotes = [ “Gratitude turns what we have into enough.”, “A thankful heart is a happy heart.”, “Joy is the simplest form of gratitude.”, “Let us be grateful to people who make us happy.”, “Gratitude unlocks the fullness of life.” ]; function addGratitude() { const input = document.getElementById(“gratitudeInput”); const list = document.getElementById(“gratitudeList”); const confirmation = document.getElementById(“confirmation”); const warning = document.getElementById(“duplicateWarning”); const thankYou = document.getElementById(“thankYou”); const quoteBox = document.getElementById(“quoteBox”); const sound = document.getElementById(“gratitudeSound”); const entry = input.value.trim(); const key = entry.toLowerCase(); const containsBadWord = blockedWords.some(word => key.includes(word)); if (entry !== “”) { if (containsBadWord) { confirmation.style.display = “none”; warning.textContent = “🚫 Please keep it kind and respectful.”; warning.style.display = “block”; setTimeout(() => { warning.style.display = “none”; }, 2500); return; } if (gratitudeEntries.has(key)) { confirmation.style.display = “none”; warning.textContent = “⚠️ You’ve already added that!”; warning.style.display = “block”; setTimeout(() => { warning.style.display = “none”; }, 2000); } else { gratitudeEntries.add(key); const item = document.createElement(“li”); const randomHeart = heartEmojis[Math.floor(Math.random() * heartEmojis.length)]; item.textContent = `${randomHeart} ${entry}`; item.style.padding = “8px 12px”; item.style.background = “#fffef8”; item.style.borderRadius = “10px”; item.style.marginBottom = “6px”; item.style.boxShadow = “0 2px 5px rgba(0,0,0,0.05)”; item.style.opacity = 0; item.style.transition = “opacity 0.5s ease-in”; list.prepend(item); setTimeout(() => { item.style.opacity = 1; }, 50); input.value = “”; warning.style.display = “none”; confirmation.style.display = “block”; thankYou.style.display = “block”; const quote = quotes[Math.floor(Math.random() * quotes.length)]; quoteBox.textContent = quote; sound.play(); setTimeout(() => { confirmation.style.display = “none”; thankYou.style.display = “none”; }, 2500); } } }