Skip to main content

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 6

Term 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));
Open Creative Coding Atelier for extra practice
What should starting a fresh round do?
Plan the week
  1. Read the lesson and explain its main idea in your own words.
  2. State the system or program’s goal and sketch its inputs, rules and output.
  3. Complete the investigation and keep the evidence listed above.
  4. Test or trace a second case and record any change it suggests.
  5. Answer the week’s check, then explain your reasoning using your evidence.

Keep your practice projects local or share them with an approved reviewer. Use fictional or nonpersonal data in your programs and tests.

Academy curriculum for family use. Course credit is subject to school and educator approval.

Quest progressProgress recorded