Getting everything ready for you…

Loading courses, problems and your progress. This takes just a moment.

0s

Projects › Beginner

Quiz App in React

A timed multiple-choice quiz with categories, scoring, a review screen and a high-score table.

Level: Beginner · Time: 3–5 days · Tech stack: React, Vite, CSS

Features to build

What you will learn

Step-by-step guide

1. Set up

npm create vite@latest quiz -- --template react. Get questions from the free Open Trivia DB API or a local JSON file.

2. Model the game as states

'start' → 'playing' → 'result'. One status variable decides which screen to show.

const [status, setStatus] = useState('start');
const [index, setIndex] = useState(0);
const [answers, setAnswers] = useState([]);

3. The timer

useEffect(() => {
  if (status !== 'playing') return;
  const t = setTimeout(() => choose(null), 15000);   // time's up
  return () => clearTimeout(t);                        // clean up on every new question
}, [index, status]);

Always clean up timers in useEffect — a classic React bug.

4. Shuffle the options

Use the Fisher–Yates shuffle once per question (not on every render — compute it when questions load).

5. Score and review

Store each answer { question, chosen, correct }. The result screen maps over them and colours right/wrong.

6. High scores

Save { name, score, date } to localStorage, sort and keep the top 5.

Level it up

On your resume

Learn on Codify