This Year's Christmas Quiz
![This Year's Christmas Quiz](/_astro/christmas-project-2023-1.C-bL7MV6_Z7KvOh.webp)
You can play it here. 🎄🎅
In 2021, I started a tradition of building a project around Christmas time. In 2021, I created a trivia quiz, and in 2022, I created a music quiz. This year, I created a trivia quiz again.
I previously wrote about how I created the 2022 quiz here. This year’s is effectively a branch of that project, with a few changes.
The main change is that I’ve added time-sensitive questions. The longer the player takes to answer the question, the fewer their points. I implemented this as it seemed that people were cheating in the public deployment (I created a separate deployment for family and friends).
The core of this feature is in the following code block. It is straightforward and contains little logic. Next year, I may refine it further and involve some scoring curve.
// Calculate time elapsed since the question startedconst elapsedTimeInSeconds = state.currentQuestionStartTime ? Math.floor((Date.now() - state.currentQuestionStartTime) / 1000) : 0;
// Calculate the score for a correct answer after time reductionconst scoreAfterTimeReduction = isCorrect ? Math.max(25 - elapsedTimeInSeconds, 1) : 0;
Merry Christmas!