Console Trivia Quiz Game
Build a trivia quiz game that runs in the terminal, written in Dart. Questions are stored in a JSON file with categories, difficulty levels, four answer options and the correct answer. The player picks a category and difficulty, answers 10 random questions by typing a number, gets instant feedback (correct, or the right answer), and sees a final score with a message. The best scores are saved to a file. It's a fun first Dart project: you'll learn classes, lists and maps, reading files and decoding JSON with dart:io and dart:convert, reading user input, and writing tests.
- Estimate
- ~8h
- Steps
- 6
- Completed by
- 0
- Proposed by
- codeseed.app
Dart SDK · dart:io
Project roadmap
- 01
Create the project and question bank
~1hInstall the Dart SDK and create a console project with dart create -t console trivia. Write data/questions.json with at least 30 questions across 3 categories and 3 difficulty levels (easy, medium, hard). Each question has a text, four options, the index of the correct option, a category and a difficulty. Done when: dart run prints Hello, and the JSON file is valid.
- 02
Load the questions into classes
~1.5hCreate a Question class with a fromJson factory constructor that checks each field: exactly four options, a correct index from 0 to 3, a known difficulty. Read the file with File.readAsStringSync and jsonDecode, and turn it into a List<Question>. If the file is missing or broken, print a clear message and exit with code 1. Done when: the program prints how many questions were loaded.
- 03
Choose a category and difficulty
~1hBefore starting, list the available categories and difficulties with numbers and read the player's choice with stdin.readLineSync. Keep asking until the input is a valid number. Include an All option for both. If fewer than 10 questions match, use all of them. Done when: the chosen filters select the right questions.
- 04
Build the game loop
~1.5hShuffle the matching questions and ask up to 10 of them one at a time: show the question number, the text and the options numbered 1 to 4, read the answer, and reject anything that isn't 1 to 4. Print Correct! or Wrong, followed by the correct answer. Done when: a full round of questions can be played in the terminal.
- 05
Show and save the score
~1.5hCount correct answers and, at the end, show the score as correct out of total and a percentage, with a message depending on the result. Ask for the player's name and save the score to scores.json, keeping the top 5 per category. Show the top 5 after each game. Done when: the high score list is saved and shown correctly across runs.
- 06
Write tests
~1.5hMove the game logic (filtering, scoring and the high score list) into classes that don't read from the terminal, so they can be tested. Write tests with package:test for parsing valid and invalid questions, filtering by category and difficulty, scoring and keeping only the top 5. Done when: dart test passes.
Resources
- DocsDart language tour
- Docsdart:io library
- DocsUsing JSON in Dart
- DocsDart testing
Ready to build this?
Get a GitHub repo and start building. Your AI reviewer checks each step as you go.
Tech stack