
Grade 12 · 18 weeks
Computer Science
Build and test a Lantern Festival scorer, model data, and design a program that people can use without giving up unnecessary personal information.
Start Week 6Term 1 · Algorithms, programs and testing
Functions and the scorekeeper
Functions can separate validation, scoring and display. Separating state changes from output helps isolate tests. A counted identifier can prevent a repeated collection from increasing the score.
Read-aloud is not available in this browser. You can still read this text on screen.
Computing lab
Run the starter and trace the supplied events. Add a special value for one lantern. Keep duplicate and unknown events at zero. Compute and print scores for two fresh rounds without sharing round state.
Keep for review. A short program, a function responsibility diagram and a trace showing that the same lantern can score in a new round.
JavaScript starter code
Save this example as a .js file and run it in Node.js or an editor your educator approves.
const lanternValues = new Map([['north', 1], ['south', 1]]);
function scoreRound(events, values) {
const collected = new Set();
let score = 0;
for (const id of events) {
if (!values.has(id) || collected.has(id)) continue;
collected.add(id);
score += values.get(id);
}
return score;
}
console.log(scoreRound(['north', 'north', 'unknown', 'south'], lanternValues));
console.log(scoreRound(['north'], lanternValues));Plan the week
- Read the lesson and explain its main idea in your own words.
- State the system or program’s goal and sketch its inputs, rules and output.
- Complete the investigation and keep the evidence listed above.
- Test or trace a second case and record any change it suggests.
- Answer the week’s check, then explain your reasoning using your evidence.

