In the last exercise, you ranked Marco’s teams with pipelines and wrapped his functions so they passed every argument through. Over the course, you’ve also built scorers that remember a total, a wrapper that runs once, a cache for lookups, and a function that walks a nested sheet. Each piece worked on its own. Quiz night needs them working together, in one kit that Marco runs at the Lantern from the first round to the final standings.
In this project, you’ll build that kit. You’ll start from Marco’s brief, work out by hand what the finished kit should report for tonight’s teams, and then build it in five steps across the next two exercises. Start with what Marco has asked for.
Read Marco’s Brief
Every week, Marco marks answer sheets at the bar, adds up scores on a notepad, and announces the winner over the noise. Last week he read the winner out twice, after a corrected score, and two teams argued about who had won. He wants his JavaScript program to do the bookkeeping. Here’s his brief. The kit should:
- Keep a running score for each team. Each team’s total belongs to that team alone, and nothing outside the scorer can change it except by adding points.
- Work out a round’s points from its answer sheet. Some rounds have categories inside categories, and every level counts.
- Show each team’s best round so far on the big screen, which asks for it again on every redraw, without repeating the work for a question it has already answered.
- Rank the teams in the final standings, highest total first, counting only the teams that played all five rounds. A team that leaves early still shows on the screen, but it isn’t ranked.
- Announce the winner a single time, however many times the announcement is triggered after a corrected score.
The kit works on the same teams you’ve used throughout the course. If you’d like to build it on your own computer as well as in the exercises, create a file named kit.js and start it with this array:
kit.js
const teams = [
{ name: "The Lamplighters", captain: "Priya",
rounds: [8, 6, 9, 7, 10] },
{ name: "Know-It-Owls", captain: "Kwame",
rounds: [7, 9, 0, 8, 6] },
{ name: "The Quizzards", captain: "Aoife",
rounds: [5, 10, 6, 9, 7] },
{ name: "Second Guessers", captain: "Diego",
rounds: [5, 9, 7, 4, 6] },
{ name: "Table Six", captain: "Mei",
rounds: [6, 8, 7, 5, 9] },
];