Skip to content
Tutorials Center
My learning

Topics

Lesson 35 of 37 ยท Projects and Practice

Mock Election Project

Plan, run and count a mock election for your class or club, compare voting methods with code, and discuss what makes an election free and fair.

The best way to understand an election is to run one. In this project you will plan a mock election, write the rules, count the ballots with two different methods and discuss the results. You can do it with your class, a club or your family, and you can use the code below to count ballots quickly.

The goal is not to find "the" correct winner. It is to see how rules shape results, and how fairness depends on details such as who may vote, how ballots are kept secret and who counts them.

Step 1: choose the question

Pick something real and harmless: the class mascot, a trip destination, a name for the school garden, or a student council officer. Choose three or four options or candidates. Keep personal topics out of it, so nobody is embarrassed by the result.

Step 2: write the rules

Agree on the rules before the vote. Use this checklist, built from the standards of free and fair elections.

Question Why it matters
Who is eligible to vote? Clear, equal rules with no unfair exclusions
One person, one vote? Equality of the vote
Is the ballot secret? Prevents pressure and bribery
Who runs the count? Independent, neutral counters, with observers
What is the voting method? Rules change outcomes; see below
How are tied results broken? A fair method, decided in advance
Can complaints be made? A fair way to challenge mistakes

Appoint an election committee of a few people who are not candidates. Give candidates equal time to present their ideas, and let observers watch the count.

Step 3: choose a voting method

Different methods can give different winners from the same votes. Here are two common ones.

  • First past the post (plurality): each voter chooses one option; the option with the most votes wins, even without a majority. It is simple and fast. It is used for national elections in countries including the UK, India and Canada.
  • Ranked choice or instant runoff: voters rank options in order of preference. If no option has more than half of the first-choice votes, the option with the fewest is removed and its ballots go to each voter's next choice. This repeats until one option has a majority. Australia uses a form of this for its lower house, and some other places use it for some elections.

A third family, proportional representation, gives parties seats in proportion to their votes; the next lesson sets exercises on it in the practice set.

Step 4: hold the vote and count

Use paper ballots. Have voters list their first, second and third choices if you will test ranked choice. Count in public, with at least two counters and an observer. Record the totals.

Counting with code

The first program counts the same ballots under both methods. It is a stand-in for a counting committee. The ballots here are invented: each is a list from first to last choice.

JS Plurality vs instant runoff

Press Run (or Ctrl + Enter) to see the console output here.

No output.

Look at what happened: the option that led in the first count did not necessarily win after the lowest candidate was eliminated and those ballots were redistributed. Neither method is "wrong". They answer slightly different questions: "who has the most first choices?" versus "who is accepted by a majority after preferences are counted?"

Step 5: check the margin and report

Always report totals, the number of ballots, invalid ballots and the margin. Publish the rules and results. The second program calculates the percentage shares and warns when the result is very close.

JS Results report

Press Run (or Ctrl + Enter) to see the console output here.

No output.

Step 6: debrief

Discuss as a group:

  1. Did every eligible person vote? Why or why not?
  2. Was the ballot secret? Did anyone feel pressured?
  3. Would a different method have changed the result?
  4. How did the candidates convince voters? Was it fair?
  5. Which rules would you change next time, and why?

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Why should election rules be agreed before the vote?

    Fair elections rely on clear rules set in advance and applied equally.
  2. 2. What is plurality voting (first past the post)?

    Plurality needs only the most votes, not more than half.
  3. 3. In instant runoff, what happens when nobody has a majority?

    The lowest option is eliminated and its votes transfer until someone passes half.
  4. 4. Which is a feature of a fair count?

    Independent counters, observers and open results build trust.

Summary

  • Choose a harmless question, write the rules first and appoint a neutral committee.
  • Free and fair elections need equal votes, secret ballots, independent counting and a way to complain.
  • Plurality needs the most votes; instant runoff counts preferences until someone has a majority.
  • Report totals, margins and invalid ballots openly, and debrief afterwards.

Next: Design a Constitution Project