A "how well do you know me" quiz looks like the easiest quiz there is: write some questions about yourself, pick the right answers, send a link, see who scores best. In practice two things decide whether it works. The questions have to be fun to guess, and the scoring and ranking have to feel fair when a group chat of friends all play at once.
This post is about both. First some question-design rules I find useful, then a small, tested JavaScript module that checks a question for common mistakes, scores an attempt, ranks the players, and makes a share token. It uses plain Node.js with no dependencies, so you can paste the blocks below, in order, into one file called quiz.mjs and run it.
One note up front: the code is a teaching example. It is not the internal implementation of any particular product, and it leaves out storage, accounts and a web server on purpose.
1. Question design: what makes a guess fun
These rules of thumb tend to help:
- Ask about habits, not trivia. "What do I order at the coffee shop?" works better than "What year was I born?". Everyone has a theory about habits, so everyone gets to guess.
- Make the wrong answers believable. If three options are silly, the question is over before it starts. Each wrong option should be something you could plausibly have chosen.
- Keep options the same shape. If the correct option is the only long, specific one, people pick it by pattern-matching instead of by knowing you.
- Use 3 or 4 options. Two is a coin flip, and five or more is tiring on a phone.
- Mix easy and hard. A few questions that nearly everyone gets right keep the quiet friends in the game. A couple of hard ones separate the close friends from the rest.
- Keep it kind. The point is laughing together. Avoid questions that are awkward to get wrong.
Several of these can be checked by a program, which is where the first helper comes in.
2. Model a question and lint it
A question only needs a prompt, a list of options and the index of the correct one:
const question = { prompt: 'What is my usual coffee order?', options: ['Flat white', 'Black americano', 'Oat latte', 'Tea, always'], correctIndex: 2, }; Before a quiz is saved, a small linter can catch the mechanical mistakes: empty text, duplicate options (after ignoring case and extra spaces), a wrong number of options, an index that points nowhere, and the "correct answer is much longer than the rest" tell. The last check is only a heuristic, so it reports a problem for you to look at rather than rejecting anything.
import { randomBytes } from 'node:crypto'; export function normalize(text) { return String(text).normalize('NFKC').trim().replace(/\s+/g, ' ').toLowerCase(); } /** * question = { prompt: string, options: string[], correctIndex: number } * Returns a list of problems (empty list = nothing found). */ export function lintQuestion(question) { const problems = []; const { prompt, options, correctIndex } = question ?? {}; if (typeof prompt !== 'string' || normalize(prompt) === '') { problems.push('prompt is empty'); } if (!Array.isArray(options)) { problems.push('options must be an array'); return problems; } if (options.length < 3 || options.length > 4) { problems.push('use 3 or 4 options'); } const seen = new Set(); for (const option of options) { const key = normalize(option); if (key === '') problems.push('an option is empty'); else if (seen.has(key)) problems.push(`duplicate option: "${key}"`); seen.add(key); } if (!Number.isInteger(correctIndex) || correctIndex < 0 || correctIndex >= options.length) { problems.push('correctIndex must point at one of the options'); return problems; } // Heuristic only: a much longer correct answer is an easy tell. const others = options.filter((_, i) => i !== correctIndex).map((o) => normalize(o).length); if (others.length > 0) { const avg = others.reduce((a, b) => a + b, 0) / others.length; const correctLen = normalize(options[correctIndex]).length; if (avg > 0 && correctLen >= avg * 1.5 && correctLen > Math.max(...others)) { problems.push('the correct option is noticeably longer than the others'); } } return problems; } normalize uses NFKC so that full-width characters like ABC compare equal to ABC. The length check compares the correct option with the average of the others and only fires when it is at least 1.5 times longer and also the longest. The 1.5 is a number I picked, not a magic constant; adjust it to taste.
3. Score an attempt
Scoring is the part where it is tempting to be clever. Keep it boring: one pick per question, and anything that is not a valid index counts as wrong.
/** * answers[i] is the index a friend picked for question i (or null/undefined). * Missing, out-of-range or non-integer answers count as wrong. */ export function scoreAttempt(questions, answers) { if (!Array.isArray(questions) || !Array.isArray(answers)) { throw new TypeError('questions and answers must be arrays'); } if (answers.length !== questions.length) { throw new RangeError('answers must have one entry per question'); } let correct = 0; questions.forEach((q, i) => { const pick = answers[i]; if (Number.isInteger(pick) && pick >= 0 && pick < q.options.length && pick === q.correctIndex) { correct += 1; } }); return { correct, total: questions.length }; } A few details here are deliberate. A list of answers with the wrong length throws, because it means the caller has a bug. A missing, out-of-range or non-integer pick, on the other hand, is just a wrong answer: it is untrusted input from a player, not a bug in your code. The string '1' does not count as the number 1.
If you build this as a web app, the usual advice applies: score on the server, and do not send the correct answers to the player's browser. Otherwise anyone who opens the network tab gets full marks.
4. Rank the players, with fair tie-breaks
A leaderboard needs a rule for ties. A common and easy-to-explain rule is: more correct answers first, then whoever finished faster. That still leaves exact ties (same score, same time), so add a final tiebreaker so that the order is always the same.
/** * entries: [{ name, correct, ms, seq }] * Order: more correct answers first, then less time, then earlier submission (seq). * Entries with the same correct AND the same ms share a rank (1, 1, 3 ...). * Returns a new array; the input is not modified. */ export function rankEntries(entries) { for (const e of entries) { if (!Number.isInteger(e.correct) || e.correct < 0) throw new RangeError(`bad score for ${e.name}`); if (!Number.isFinite(e.ms) || e.ms < 0) throw new RangeError(`bad time for ${e.name}`); if (!Number.isInteger(e.seq)) throw new RangeError(`bad seq for ${e.name}`); } const sorted = [...entries].sort( (a, b) => b.correct - a.correct || a.ms - b.ms || a.seq - b.seq, ); let rank = 0; return sorted.map((e, i) => { const prev = sorted[i - 1]; const tied = prev && prev.correct === e.correct && prev.ms === e.ms; if (!tied) rank = i + 1; return { ...e, rank }; }); } Two things to notice. Exactly tied players share a rank, and the next rank is skipped, so you get 1, 1, 3, as in many sports tables. And the function returns a new array instead of sorting the one you passed in, so the caller's data is never changed behind its back.
About time: if you use "time to finish" as a tie-break, measure it on the server, from the moment the questions were handed out to the moment the answers arrived. A number sent by the browser is easy to fake and easy to get wrong. Also decide what the clock covers. For example, you may not want time spent writing a message after the quiz to count against a player.
5. Share links should be hard to guess
If a whole quiz is reached through a single shared link, that link should not be something you can count through, like /quiz/1, /quiz/2. Random bytes work well for this:
/** An unguessable share token: 9 random bytes -> 12 URL-safe characters. */ export function newShareToken(bytes = randomBytes) { const buf = bytes(9); if (buf.length !== 9) throw new RangeError('expected 9 bytes'); return Buffer.from(buf).toString('base64url'); } Nine random bytes become 12 URL-safe characters (base64url). The optional bytes parameter exists so a test can inject fixed bytes. Notice that this is not a security feature on its own: if a quiz needs to be private, you still need real access rules on the server.
6. Test it
With the module in quiz.mjs and the tests in quiz.test.mjs, run:
node --test These are cases worth having, and a reasonable starting set if you write your own:
- duplicate options that only differ by case or spacing,
- a wrong-length answers array, which should throw,
-
null,undefined,7and'1'as picks, which should all count as wrong, - exact ties, and zero scores, in the ranking,
- the ranking function not mutating its input,
- tokens that match the expected format over a few hundred runs.
I ran all 15 tests of my version with Node 24 and they passed. Passing tests only show that those cases work, so add the ones that match your own rules.
A real-world example
If you would rather see the idea in action than build it, Quiz My Tree is a free "how well do you know me" Christmas quiz. As described on its site, you choose 10, 20 or 30 questions about yourself, tap your own answers, pick a scene and share one link. Friends who play get a place on your tree ranked by score, with faster finishers ranked higher when scores are tied, and each friend gets one try. Friends can also leave an optional letter or voice note that stays sealed until December 25. Saving a quiz requires signing in.
I have only used the public site, and I do not know how it is built, so please treat the code above as my own sketch of the problem and not as a description of how that product works.
Summary
- Write questions about habits, with believable wrong answers of similar length.
- Lint questions mechanically (empty text, duplicates, option count, bad index) and use heuristics like the length check only as a warning.
- Score on the server, treat player picks as untrusted, and count invalid picks as wrong.
- Rank by score, then time, then a stable final tiebreaker. Let exact ties share a rank.
- Use random share tokens, and add real access control if privacy matters.
- Test the awkward cases: ties, zero scores, bad input.
If you have a question format that works well in your friend group, I would like to hear about it in the comments.
