Mini project
Quiz App with HTML, CSS and JavaScript
A browser quiz app that loads questions from a JSON file, shows one question at a time with a timer, scores answers, and saves the best score with localStorage.
HTMLCSSJavaScriptJSONlocalStorage
The problem
Students revise better with quick quizzes, and teachers want an easy way to make one without signing up for a service. This project is a small quiz that runs in any browser, with questions kept in a separate JSON file so anyone can change them without touching the code.
Features to build
- Load questions from a questions.json file with fetch
- Show one question with four options, and move to the next after an answer
- Highlight the correct answer and the chosen answer after each question
- A countdown timer per question that moves on when time runs out
- A final screen with the score, percentage and a review of wrong answers
- Save and show the best score using localStorage
- Works on mobile screens
Suggested data model
[
{
"question": "Which keyword declares a variable that cannot be reassigned?",
"options": ["var", "let", "const", "static"],
"answer": 2
}
]answer is the index of the correct option, so the check is a simple comparison.
Build plan
- 1
Build the layout
Write the HTML for a start screen, a question screen and a result screen, and style them with Flexbox. Show one screen at a time with a CSS class.
- 2
Load the questions
Use fetch and await response.json(). Show an error message if the file cannot be loaded.
- 3
Render a question
Create the option buttons with document.createElement from the current question, so the HTML has no hard-coded questions.
- 4
Check answers and score
Use one click listener on the options container (event delegation), compare the clicked index with answer, update the score, then show the next question.
- 5
Add the timer
Use setInterval to count down, and clear it with clearInterval when the user answers so timers never stack up.
- 6
Results and best score
Show the score and a list of wrong answers. Read and write the best score with localStorage.getItem and setItem.
- 7
Publish it
Put the project on GitHub and publish it free with GitHub Pages, then add the live link to your README.
Learn these first
Each part of the project is taught in one of these free lessons.
- Introduction to the DOM: How JavaScript Sees and Changes Web Pages
- Creating and Removing DOM Elements: createElement, append, remove and Templates
- JavaScript Events: addEventListener, the Event Object and Common Events
- Event Bubbling, Capturing and Event Delegation in JavaScript
- JavaScript Arrays: Creating, Accessing, Adding and Removing Items
- Fetching Data from APIs with JavaScript fetch()
- localStorage and sessionStorage in JavaScript: Saving Data in the Browser
- Project: Publish a Portfolio Website with GitHub Pages
Make it stand out
- Categories and difficulty levels chosen on a start screen
- Shuffle questions and options on every attempt
- Keyboard support: press 1 to 4 to answer
- A page where a teacher can add questions and download a new questions.json
Viva and interview questions
Try to answer each one aloud before you open it.
Why keep the questions in a JSON file?
It separates data from code. Anyone can add or change questions by editing the JSON, and the same code works for any quiz.
What is event delegation and where did you use it?
Instead of adding a listener to every option button, I add one listener to their parent and check which button was clicked using
event.target. It works even for buttons created later.Why does fetch not work when you open index.html directly from the folder?
Browsers block fetch requests from
file://pages for security. Running a small local server, or publishing on GitHub Pages, serves the files over HTTP so fetch works.How does localStorage work?
It stores string key-value pairs in the browser for that site, and they stay after the browser closes. I store the best score as a string and convert it back with
Number().How do you stop two timers running at once?
I keep the interval id from
setIntervaland callclearIntervalwith it before starting a new timer and when an answer is chosen.
What to put in your project report
- Abstract: the problem, your solution and the result in one paragraph.
- Introduction and problem statement: who has the problem and why it matters.
- Requirements: the features (functional) and qualities such as speed and security (non-functional).
- Design: architecture diagram, database tables or data flow, and screen layouts.
- Implementation: the main modules and the most interesting code, explained.
- Testing: the test cases you ran, with inputs, expected and actual results.
- Results: screenshots or numbers that show the project working.
- Conclusion and future scope: what you achieved and what you would add next.
Your college may give its own format. Follow that first, and use this list to check nothing is missing.
More project ideas
- Personal Portfolio Website with HTML and CSSMini project
- Snake Game with JavaScript and CanvasMini project
- Typing Speed Test with JavaScriptMini project