Step 3: Score, next question and finish
A quiz needs a flow: the current index, a running score, a Next question button and a final screen. When index passes the last question the component returns a different result screen. Resetting is just setting the three pieces of state back to their starting values.
Play through to the end. Look at how choose(i) updates two things at once, the selection and the score, and how the finish condition (index >= QUESTIONS.length) is derived rather than stored.
Write scoreQuiz(answers, key) that counts how many entries of answers equal the entry at the same position in key. Print scoreQuiz([0, 1, 1, 0], [0, 1, 2, 0]) and scoreQuiz([], []).
How does the app know the quiz is finished?
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.