A timed quiz app
The problem
Build a quiz in React that shows one question at a time with a countdown, records answers, and ends with a score and a review of each question.
Requirements
- Questions held as data, with any number of options each
- A countdown per question made with an effect and an interval that is always cleaned up
- Keyboard support: number keys choose an answer and Enter moves on, with focus moved by refs
- The quiz's progress managed by a reducer with started, answered, timedOut and restarted actions
- A results screen with the score and each question's correct answer
Technologies
- React
- useEffect
- useRef
- useReducer
Step by step
- Design the states of the quiz (not started, in progress, finished) and the actions between them.
- Write the reducer and test every action as a plain function.
- Build the question screen, then the timer effect with its cleanup.
- Add keyboard handling and focus management.
- Add the results screen and a restart button.
Expected result
A quiz app that handles timing, keyboard use and restarting correctly, built around a reducer.
How it is evaluated
- No interval keeps running after a question or the quiz ends
- Every action of the reducer is tested
- The quiz can be completed with the keyboard only
- Restarting resets everything without reloading the page
Ways to improve it
- Shuffle questions and options
- Add categories chosen before starting
- Show a progress bar and a best score kept between visits