MSK Institute LogoMSK.Institute
HomeCourses
Book Free Demo➔Sign In
Free Demo➔
MSK Institute LogoMSK.Institute

Leading computer training academy in Shikohabad for software engineering, Python, web development, and digital literacy.

ISO 9001:2015 Certified Center
Follow & Connect
4.9

Programs & Admissions

  • All CoursesCatalog
  • Learning PathsRoadmaps
  • Student ProjectsShowcase
  • Live Classes & ScheduleLive
  • Upcoming Batches
  • Campuses & LocationsHub
  • Verify Certificates
  • Book Free Demo Class

Resources & Tools

  • Free Online Mock TestsAll Tests
  • NIELIT CCC Mock TestFree
  • Course & Career FinderQuiz
  • Study Material Hub
  • All MSK ToolsHub
  • Keyboard ShortcutsNew
  • TypeQuest Speed LabTyping
  • MSK Code PlaygroundCode
  • Interactive Tutorials
  • Quick Cheatsheets

Institute & Contact

  • About MSK Institute
  • Careers & InternshipsHiring
  • Publications & Blogs
  • Gali No. 3, Near Gyan Jyoti Public School,
    Adarsh Nagar, Shikohabad, Uttar Pradesh 283135
  • +91 83930 42166
  • mskshikohabad@gmail.com
  • Hours:Mon – Sat: 8:00 AM – 7:00 PM | Sun: 10:00 AM – 2:00 PM
  • 4.9 ★(38 Google Reviews)
© 2026 MSK Institute. All rights reserved.•Privacy Policy•Terms of Service•Disclaimer•Contact Us

Shikohabad's Leading Computer & Coding Academy

Home
Courses
Live
Material
Quiz App0%
Study Materials
JavaScript for IntermediateProgress 0%
1.1Block Scope with let & const1.2Template Literals1.3Destructuring Arrays and Objects1.4Default Parameters1.5Enhanced Object Literals
14.1Quiz App14.2To-Do List with Local Storage14.3Product Filter App
HomeTutorialsJavaScript for IntermediateQuiz App
To-Do List with Local Storage

Quiz App

Beginner12 min read•Updated: 2026-09-15•By Er. Sumit Kumar (MSK Institute)
Study Materials

In this project, you will build a dynamic, interactive Quiz App featuring question pools, dynamic DOM rendering, score tracking, interactive progress indicators, and instant feedback.


1. Project Specifications

  1. 1
    Question Data Structure: Array of question objects containing question prompt, options array, correct answer index, and explanation.
  2. 2
    State Management: Track active question index, score count, user answers, and completion state.
  3. 3
    Dynamic Rendering: Rebuild question cards dynamically with high-performance DOM methods.
  4. 4
    Instant Feedback: Highlight correct answer in green and incorrect selection in red upon clicking.
  5. 5
    Scorecard & Restart: Render final scorecard with percentage and a restart button that resets state.

2. HTML Markup (index.html)

1<!DOCTYPE html>
2<html lang="en">
3<head>
4 <meta charset="UTF-8" />
5 <meta name="viewport" content="width=device-width, initial-scale=1.0" />
6 <title>JavaScript Mastery Quiz</title>
7 <link rel="stylesheet" href="style.css" />
8</head>
9<body>
10 <div class="quiz-container" id="quiz-app">
11 <header class="quiz-header">
12 <h2>JavaScript Skills Assessment</h2>
13 <div class="progress-bar-container">
14 <div id="progress-bar" class="progress-bar"></div>
15 </div>
16 <div class="stats-row">
17 <span id="question-tracker">Question 1 of 5</span>
18 <span id="score-tracker">Score: 0</span>
19 </div>
20 </header>
21 
22 <main id="quiz-card" class="quiz-card">
23 <h3 id="question-text" class="question-text">Loading question...</h3>
24 <div id="options-container" class="options-container"></div>
25 <div id="explanation-box" class="explanation-box hidden"></div>
26 </main>
27 
28 <footer class="quiz-footer">
29 <button id="next-btn" class="btn btn-primary hidden">Next Question</button>
30 </footer>
31 
32 <!-- Results Modal / Card -->
33 <div id="results-card" class="results-card hidden">
34 <h2>Quiz Completed!</h2>
35 <p id="final-score-text">You scored 0 out of 5</p>
36 <div id="score-percentile" class="score-badge">0%</div>
37 <button id="restart-btn" class="btn btn-restart">Retake Quiz</button>
38 </div>
39 </div>
40 
41 <script src="app.js"></script>
42</body>
43</html>

3. Styling the Quiz (style.css)

1:root {
2 --primary: #4f46e5;
3 --success: #10b981;
4 --danger: #ef4444;
5 --bg: #0f172a;
6 --card-bg: #1e293b;
7 --text: #f8fafc;
8 --text-muted: #94a3b8;
9 --border: #334155;
10}
11 
12body {
13 margin: 0;
14 font-family: system-ui, -apple-system, sans-serif;
15 background-color: var(--bg);
16 color: var(--text);
17 min-height: 100vh;
18 display: flex;
19 align-items: center;
20 justify-content: center;
21 padding: 1rem;
22}
23 
24.quiz-container {
25 background: var(--card-bg);
26 border-radius: 1rem;
27 max-width: 600px;
28 width: 100%;
29 padding: 2rem;
30 box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
31}
32 
33.progress-bar-container {
34 background: var(--border);
35 height: 8px;
36 border-radius: 4px;
37 overflow: hidden;
38 margin: 1rem 0;
39}
40 
41.progress-bar {
42 background: var(--primary);
43 height: 100%;
44 width: 0%;
45 transition: width 0.3s ease;
46}
47 
48.stats-row {
49 display: flex;
50 justify-content: space-between;
51 font-size: 0.9rem;
52 color: var(--text-muted);
53}
54 
55.question-text {
56 font-size: 1.25rem;
57 margin: 1.5rem 0;
58}
59 
60.options-container {
61 display: flex;
62 flex-direction: column;
63 gap: 0.75rem;
64}
65 
66.option-btn {
67 background: #334155;
68 color: var(--text);
69 border: 1px solid var(--border);
70 padding: 1rem;
71 border-radius: 0.5rem;
72 text-align: left;
73 font-size: 1rem;
74 cursor: pointer;
75 transition: all 0.2s;
76}
77 
78.option-btn:hover:not(:disabled) {
79 background: #475569;
80}
81 
82.option-btn.correct {
83 background: var(--success);
84 border-color: var(--success);
85 color: white;
86}
87 
88.option-btn.wrong {
89 background: var(--danger);
90 border-color: var(--danger);
91 color: white;
92}
93 
94.explanation-box {
95 margin-top: 1rem;
96 padding: 1rem;
97 background: rgba(79, 70, 229, 0.1);
98 border-left: 4px solid var(--primary);
99 border-radius: 0.25rem;
100 font-size: 0.95rem;
101}
102 
103.btn {
104 padding: 0.75rem 1.5rem;
105 border-radius: 0.5rem;
106 border: none;
107 font-weight: 600;
108 cursor: pointer;
109 margin-top: 1.5rem;
110}
111 
112.btn-primary { background: var(--primary); color: white; }
113.btn-restart { background: var(--success); color: white; }
114.hidden { display: none !important; }

4. Application Logic (app.js)

1// Quiz Data Repository
2const questions = [
3 {
4 question: "What does Array.prototype.map() return?",
5 options: [
6 "The original array mutated",
7 "A new array of identical length with transformed values",
8 "A single reduced value",
9 "A boolean indicating matching condition"
10 ],
11 answer: 1,
12 explanation: "map() constructs a new array with results from calling the callback on each element."
13 },
14 {
15 question: "Which keyword creates a block-scoped variable in modern JavaScript?",
16 options: ["var", "let", "global", "scope"],
17 answer: 1,
18 explanation: "let and const provide true block-level scoping within curly braces."
19 },
20 {
21 question: "What does Promise.all() do when one of the promises rejects?",
22 options: [
23 "Waits for all to finish",
24 "Immediately rejects with that error (fail-fast)",
25 "Retries the rejected promise",
26 "Returns null"
27 ],
28 answer: 1,
29 explanation: "Promise.all is fail-fast: the first rejection immediately rejects the whole batch."
30 }
31];
32 
33// State
34let currentIndex = 0;
35let score = 0;
36 
37// Elements
38const questionText = document.querySelector('#question-text');
39const optionsContainer = document.querySelector('#options-container');
40const explanationBox = document.querySelector('#explanation-box');
41const nextBtn = document.querySelector('#next-btn');
42const progressBar = document.querySelector('#progress-bar');
43const questionTracker = document.querySelector('#question-tracker');
44const scoreTracker = document.querySelector('#score-tracker');
45const quizCard = document.querySelector('#quiz-card');
46const resultsCard = document.querySelector('#results-card');
47const finalScoreText = document.querySelector('#final-score-text');
48const scorePercentile = document.querySelector('#score-percentile');
49const restartBtn = document.querySelector('#restart-btn');
50 
51function renderQuestion() {
52 const currentQ = questions[currentIndex];
53 questionText.textContent = currentQ.question;
54 explanationBox.classList.add('hidden');
55 nextBtn.classList.add('hidden');
56 optionsContainer.innerHTML = '';
57 
58 // Progress Bar update
59 const progressPercent = ((currentIndex) / questions.length) * 100;
60 progressBar.style.width = `${progressPercent}%`;
61 questionTracker.textContent = `Question ${currentIndex + 1} of ${questions.length}`;
62 
63 currentQ.options.forEach((optText, index) => {
64 const btn = document.createElement('button');
65 btn.className = 'option-btn';
66 btn.textContent = optText;
67 btn.addEventListener('click', () => handleAnswer(index, btn));
68 optionsContainer.appendChild(btn);
69 });
70}
71 
72function handleAnswer(selectedIndex, selectedBtn) {
73 const currentQ = questions[currentIndex];
74 const buttons = optionsContainer.querySelectorAll('.option-btn');
75 
76 // Disable all options
77 buttons.forEach(btn => btn.disabled = true);
78 
79 // Check correctness
80 if (selectedIndex === currentQ.answer) {
81 selectedBtn.classList.add('correct');
82 score++;
83 scoreTracker.textContent = `Score: ${score}`;
84 } else {
85 selectedBtn.classList.add('wrong');
86 // Highlight correct answer
87 buttons[currentQ.answer].classList.add('correct');
88 }
89 
90 // Show explanation
91 explanationBox.textContent = currentQ.explanation;
92 explanationBox.classList.remove('hidden');
93 
94 // Reveal next button
95 nextBtn.classList.remove('hidden');
96}
97 
98nextBtn.addEventListener('click', () => {
99 currentIndex++;
100 if (currentIndex < questions.length) {
101 renderQuestion();
102 } else {
103 showResults();
104 }
105});
106 
107function showResults() {
108 quizCard.classList.add('hidden');
109 nextBtn.classList.add('hidden');
110 resultsCard.classList.remove('hidden');
111 progressBar.style.width = '100%';
112 
113 const percent = Math.round((score / questions.length) * 100);
114 finalScoreText.textContent = `You scored ${score} out of ${questions.length}`;
115 scorePercentile.textContent = `${percent}%`;
116}
117 
118restartBtn.addEventListener('click', () => {
119 currentIndex = 0;
120 score = 0;
121 scoreTracker.textContent = 'Score: 0';
122 resultsCard.classList.add('hidden');
123 quizCard.classList.remove('hidden');
124 renderQuestion();
125});
126 
127// Initialize
128renderQuestion();

Interactive Quiz• Knowledge Check

Practice Quiz

Question 1
Why are all option buttons disabled immediately after the user selects an answer in handleAnswer()?
Question 2
How is the progress bar width updated dynamically as the user advances through questions?
Question 3
What happens to the options container before rendering a new question?
Question 4
Which CSS class is applied to highlight the correct answer button in green?
Question 5
What resets the quiz back to the initial state when clicking the restart button?
Next Lesson

To-Do List with Local Storage

Continue learning with hands-on practice, examples, and exercises in the upcoming topic.

Related Lessons

Previous LessonNext Lesson
Network Tab for API CallsTo-Do List with Local Storage

Practice Quiz

Test your understanding of this lesson with 5 questions. Each question has one correct answer.

Mentor-Led Practical Training

Master JavaScript for Intermediate with Hands-On Projects

Practice in live mentor-led sessions with real projects, mock tests, and verifiable certification at MSK Institute.

View Full CourseBook Free Demo
PreviousNext
PreviousPrevNext