WeCodeAcademy

Step 6: Review screen and best score

A good quiz lets you learn from mistakes. Store every answer in an array instead of only the score; then the score is derived (answers.filter(...)) and a Review component can list each question with ✓ or ✗ and the correct answer. The best score is remembered with localStorage, wrapped in try/catch because storage can be blocked (as it is inside this preview, so the best score here only lasts while the page is open).

Examplereact
Open in editor »

Finish the quiz and look at the review. This is lifting the right state up: storing the answers (the source of truth) means everything else can be calculated from them.

Quick check

Why store the list of answers instead of only a running score?

Finish the quick check (and any code exercise) to complete this lesson, or mark it done yourself.

Tip: use the left and right arrow keys to move between lessons.