Skip to content
Tutorials Center
My learning

Topics

Lesson 67 of 77 ยท Projects

Project: A Mock Interview Runner

Build a mock interview runner in JavaScript: seeded random question selection, a countdown timer, rubric scoring and a final report you can run.

A mock interview is the best practice you can get, but it needs a partner, a clock and a way to score yourself fairly. In this project you build a small program that plays the interviewer: it picks questions from a bank, times your answers, scores them against a rubric and prints a report that shows what to practice next.

You will write it in plain JavaScript in four steps. To keep every run reproducible, the random generator is seeded and the clock is simulated, which are the same tricks you used to tame flaky tests in Testing and Code Quality Questions. The finished design can later be wired to a real timer and a real text box.

The runner's four parts

Picker Chooses questions by topic and difficulty.
Timer Gives each question a time budget.
Rubric Scores each answer on fixed criteria.
Report Totals, weak spots, next steps.

Small parts that you can test one by one.

1 / 2

Step 1: pick questions at random, fairly

A good interview mixes topics and difficulty, and it should not repeat questions. Picking by Math.random() makes bugs impossible to reproduce, so use a small seeded generator instead. Given the same seed you always get the same interview, and a different seed gives a fresh one.

The picker filters the bank by the requested topics, shuffles with the Fisher-Yates algorithm (which gives every ordering equal probability, unlike the popular but biased sort(() => Math.random() - 0.5) trick), and takes the first N.

JS Step 1: a seeded picker

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

No output.

The first and third lines are identical because the seed matches. That is exactly what you want when a friend says "try interview number 42".

Step 2: a timer with an injected clock

Real interviews have time limits, and the runner should mark an answer as late when it takes too long. Instead of reading Date.now() all over the code, give the runner a clock object with a now() method. In production it wraps the real time; in tests and in this lesson it is a fake that you advance by hand.

Each question gets a budget in seconds, scaled by difficulty. The timer records how long the answer took and flags it as onTime or late.

JS Step 2: budgets and a fake clock

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

No output.

A real implementation would also show a countdown and might warn at 80% of the budget. Because the clock is injected, you could test that behavior by advancing the fake clock in steps.

Step 3: score answers with a rubric

Self-scoring is hard unless you decide the criteria in advance. A rubric lists what a good answer contains and gives each criterion a weight. Use criteria that real interviewers use: correctness, clarity, trade-offs, and a concrete example. Each is graded 0, 1 or 2 (missing, partial, strong).

The score for a question is the weighted sum scaled to 100, minus a small penalty when the answer was late. Keep the penalty modest: running slightly over time is a smaller problem than a wrong answer.

JS Step 3: a weighted rubric

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

No output.

Notice how correctness carries the most weight: a correct but terse answer and a wrong but polished one both land on 50, so polish alone can never lift a wrong answer above a solid one. The rubric rewards substance, but does not ignore communication.

Step 4: run an interview and print a report

Now combine the parts. The runner picks questions, asks each one through the clock, scores it from a scripted set of grades (your self-assessment in the real app) and builds a report with the total, a per-topic average and a list of weak spots below a threshold.

JS Step 4: the full runner and report

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

No output.

The report is where the value is. A single low score means little, but a topic average under your threshold across several runs tells you what to study. Feed those topics back into the flashcard trainer from the previous project.

Ideas to extend it

  • Difficulty ramp: start easy and give a harder follow-up when the score is above 80.
  • Follow-up questions: each bank entry can list a deeper question to ask when the first one went well.
  • Real timer: replace the fake clock with { now: () => Date.now() / 1000 } and show a countdown.
  • History: save each report as JSON and chart the average per topic over weeks.
  • Peer mode: let a friend enter the grades, which removes the temptation to be generous with yourself.
  • Tests: assert that the same seed gives the same picks, that late answers lose exactly the penalty, and that invalid grades are rejected.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Why does the runner use a seeded random generator instead of Math.random()?

    Reproducibility is the point. Given a seed, tests and friends can get exactly the same sequence of questions.
  2. 2. What is the benefit of injecting a clock object?

    A fake clock can be advanced by hand, so timing behavior is deterministic and fast to test.
  3. 3. Why is Fisher-Yates preferred over sort(() => Math.random() - 0.5) for shuffling?

    Sorting with a random comparator is inconsistent and biased. Fisher-Yates gives each permutation the same chance.
  4. 4. In the rubric, why does correctness have the highest weight?

    Weights express priorities. A correct answer with weaker delivery should beat a polished wrong one.

Summary

  • Pick questions with a seeded generator and an unbiased Fisher-Yates shuffle so interviews are reproducible.
  • Inject a clock to give each question a time budget and test timing without waiting.
  • Score with a weighted rubric of 0 to 2 grades, with a modest penalty for lateness.
  • A report with per-topic averages shows what to study next.
  • Keep every part small and pure so the runner is easy to test and extend.

Next: Project: A Mini Online Judge.