Urgent.News

What's breaking now, across thousands of outlets.

Tech

A "Daily Challenge" That Resets at Midnight: Deterministic Picks Without a Backend

Daily challenges are one of the simplest engagement features you can add to a games site — Wordle made the pattern famous. On Classroom Games , a collection of free learning games for teachers (math, typing, spelling, reading comprehension, geography, fractions, multiplication, sight words, brain breaks and more), the homepage shows one "Today's Pick" with a points goal. It resets at midnight,…

Daily challenges, featured prominently on platforms like Classroom Games, are simple yet effective engagement tools. These challenges, such as Wordle's popular "Today's Pick," grant users a single point opportunity each day. The unique aspect of this feature is its ability to function independently, without requiring a backend server.

The key to making this happen lies in utilizing the local date, derived from the player's device, rather than a global timestamp. This ensures that users in different time zones, like a classroom in California or one in Paris, receive a fresh challenge when their individual day begins. The function localDateKey calculates this local date key using the getFullYear, getMonth, and getDate methods from the Date object, ensuring the date format remains consistent regardless of time zone.

Once the local date key is established, the next step is to pick a challenge deterministically from that date. To do this, the date string is hashed using the FNV-1a algorithm, a tiny and fast hashing function suitable for selecting an item from a list. The resulting hash is then used to index into an array of predefined categories (math, typing, reading, etc.) to determine the day's challenge.

To prevent users from receiving the same challenge back-to-back, the algorithm includes a secondary check against the previous day's challenge. If a collision occurs, the algorithm steps forward to the next category, ensuring variety and user satisfaction. This method maintains the randomness of the selection while preventing redundant challenges.

Finally, to track user progress, the status of the challenge (Not started, in progress, or goal reached) is stored locally in the browser's localStorage, using the local date key as the identifier. This approach allows for seamless tracking without the need for a server, making the feature accessible and easy to implement on any games site.

Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

Read the original at dev.to →

More in Tech

More from Friday 25 September →