Build a Classroom Quiz Scorer
Scenario
Use the answer key [A, B, C]. An answer earns one point if it matches at the same position. Return the count, and report invalid input when lengths differ.
Try it yourself
Predict each outcome, then turn the examples into tests before you code.
| Case | Result |
|---|---|
| [A, X, C] | Select a choice above to see what happens. |
| [C, A, B] | Select a choice above to see what happens. |
| [A, B] | Select a choice above to see what happens. |
Reveal the explanation
- [A, X, C]
Expected 2. The first and third answers match.
- [C, A, B]
Expected 0. None matches at its position.
- [A, B]
Expected invalid input. The answer count differs from the key.
Draw the length check before the loop. Ask the agent to return only the count or invalid-input result, then inspect how it matches positions and stops.
Download shared test cases
Your turn
Build the scorer and test partial matches, a shifted array, and unequal lengths.
Common mistake Counting an answer that occurs elsewhere in the key.
Check your work
The results are 2, 0, and invalid input for the three given examples.
Project brief
- Basic
- Trace the given answers with a table of position, expected letter, actual letter, and running score.
- Intermediate
- Implement the scorer and test partial matches, all incorrect answers, and unequal lengths.
- Stretch
- Add empty input and a valid all-correct example. Reuse those cases when porting the scorer to a second language.
What to hand in
Include your diagram, expected-result table, code, actual test output, and the commit or diff you reviewed.
Review criteria
- Logic · Your diagram shows every required path and boundary.
- Verification · The tests exercise the stated acceptance cases and the recorded results match the code.
- Review · The change is focused and you can explain the decision it implements.
This browser could not save your progress. Changes last until you leave the page.