Course Content
Project file
0/1
Complete Web Designing Course for Beginners

Lesson 7.6 – Quiz Application Project

πŸš€ Building a Complete Interactive Quiz System Using HTML, CSS & JavaScript


🎯 Learning Objectives

After completing this lesson, students will be able to:

βœ… Build a Quiz Application

βœ… Display Questions Dynamically

βœ… Check Answers

βœ… Calculate Score

βœ… Use Arrays & Objects

βœ… Use DOM Manipulation

βœ… Build Real-World Educational Applications


πŸ“– Introduction

Quiz systems are widely used in:

βœ… Online Exams

βœ… School Tests

βœ… College Assessments

βœ… Competitive Exam Platforms

βœ… Learning Management Systems (LMS)


Examples:

Β 
Question:

What does HTML stand for?

A. Hyper Text Markup Language

B. High Text Machine Language

C. Hyper Transfer Markup Language

D. Home Tool Markup Language

[ Submit ]
Β 

Today we will build:

🧠 Quiz Application Project


🌟 Project Preview

Β 
----------------------------------

JavaScript Quiz

Question 1 of 3

What does HTML stand for?

( ) Option A

( ) Option B

( ) Option C

( ) Option D

[ Next Question ]

----------------------------------
Β 

After the last question:

Β 
Quiz Completed

Your Score: 3 / 3
Β 

🎯 Concepts Used

Concept Used
Arrays βœ…
Objects βœ…
Functions βœ…
Events βœ…
DOM Manipulation βœ…
Conditional Statements βœ…

πŸ—‚οΈ Project Files

Create:

index.html

style.css

script.js

🎯 Step 1 – Create HTML Structure

index.html

<!DOCTYPE html>

<html>

<head>

<title>Quiz Application</title>

<link rel="stylesheet" href="style.css">

</head>

<body>

<div class="container">

<h1>JavaScript Quiz</h1>

<h2 id="question"></h2>

<div id="options"></div>

<button onclick="nextQuestion()">

Next Question

</button>

<h2 id="result"></h2>

</div>

<script src="script.js"></script>

</body>

</html>

🎯 Step 2 – Design the Interface

style.css

body{

font-family:Arial;

background:#f4f4f4;

display:flex;

justify-content:center;

align-items:center;

height:100vh;

}

.container{

background:white;

padding:30px;

width:600px;

border-radius:10px;

box-shadow:0 0 15px lightgray;

text-align:center;

}

button{

padding:10px 20px;

background:#0d6efd;

color:white;

border:none;

border-radius:5px;

cursor:pointer;

margin-top:20px;

}

button:hover{

background:#084298;

}

.option{

margin:10px;

padding:10px;

background:#f1f1f1;

border-radius:5px;

text-align:left;

}

🎯 Step 3 – Create Quiz Questions

script.js

let quiz =

[
{
question:
"What does HTML stand for?",

options:
[
"Hyper Text Markup Language",
"High Text Machine Language",
"Hyper Transfer Markup Language",
"Home Tool Markup Language"
],

answer:
"Hyper Text Markup Language"
},

{
question:
"Which language is used for styling websites?",

options:
[
"HTML",
"CSS",
"Python",
"Java"
],

answer:
"CSS"
},

{
question:
"Which keyword creates a function?",

options:
[
"method",
"function",
"define",
"create"
],

answer:
"function"
}
];

🌟 Understanding Objects

Each question is stored as an object.

Example:

{
question:"What is HTML?",

options:[...],

answer:"Hyper Text Markup Language"
}

🎯 Create Variables

let currentQuestion = 0;

let score = 0;

🌟 What Do They Store?

Β 
currentQuestion
Β 

Stores question number.


Β 
score
Β 

Stores correct answers.


🎯 Display Question Function

function loadQuestion()
{

}

Get Current Question:

let q =

quiz[currentQuestion];

Display Question:

document.getElementById("question").innerHTML =

q.question;

🎯 Display Options

let optionsHTML = "";

Loop Through Options

for(let i=0;i<q.options.length;i++)
{
}
Β 

Create Radio Button

optionsHTML +=

'<div class="option">' +

'<input type="radio"

name="answer"

value="' + q.options[i] + '">' +

q.options[i] +

'</div>';

Display Options

document.getElementById("options").innerHTML =

optionsHTML;

🌟 Complete loadQuestion()

function loadQuestion()
{

let q = quiz[currentQuestion];

document.getElementById("question").innerHTML =

q.question;

let optionsHTML = "";

for(let i=0;i<q.options.length;i++)
{

optionsHTML +=

'<div class="option">' +

'<input type="radio"

name="answer"

value="' + q.options[i] + '">' +

q.options[i] +

'</div>';

}

document.getElementById("options").innerHTML =

optionsHTML;

}

🎯 Check Answer

Create Function:

function nextQuestion()
{

}

Get Selected Answer

let selected =

document.querySelector(
'input[name="answer"]:checked'
);

Check Selection

if(!selected)
{

alert("Please Select An Answer");

return;

}

🌟 Compare Answer

if(

selected.value ==

quiz[currentQuestion].answer

)

{

score++;

}

Correct answer increases score.


🎯 Move To Next Question

currentQuestion++;

🌟 Check Quiz Completion

if(currentQuestion < quiz.length)
{

loadQuestion();

}
else
{

showResult();

}

🎯 Display Final Result

function showResult()
{

document.getElementById("question").innerHTML =

"Quiz Completed";

document.getElementById("options").innerHTML = "";

document.getElementById("result").innerHTML =

"Your Score: " +

score +

" / " +

quiz.length;

}

🌟 Complete nextQuestion()

function nextQuestion()
{

let selected =

document.querySelector(
'input[name="answer"]:checked'
);

if(!selected)
{

alert("Please Select An Answer");

return;

}

if(

selected.value ==

quiz[currentQuestion].answer

)

{

score++;

}

currentQuestion++;

if(currentQuestion < quiz.length)
{

loadQuestion();

}
else
{

showResult();

}

}

🎯 Start Quiz Automatically

At end of script:

loadQuestion();

πŸ’» Complete JavaScript Code

script.js

let quiz =
[
{
question:"What does HTML stand for?",
options:[
"Hyper Text Markup Language",
"High Text Machine Language",
"Hyper Transfer Markup Language",
"Home Tool Markup Language"
],
answer:"Hyper Text Markup Language"
},

{
question:"Which language is used for styling websites?",
options:[
"HTML",
"CSS",
"Python",
"Java"
],
answer:"CSS"
},

{
question:"Which keyword creates a function?",
options:[
"method",
"function",
"define",
"create"
],
answer:"function"
}
];

let currentQuestion = 0;

let score = 0;

function loadQuestion()
{

let q = quiz[currentQuestion];

document.getElementById("question").innerHTML =
q.question;

let optionsHTML = "";

for(let i=0;i<q.options.length;i++)
{

optionsHTML +=

'<div class="option">' +

'<input type="radio" name="answer" value="' +

q.options[i] +

'">' +

q.options[i] +

'</div>';

}

document.getElementById("options").innerHTML =
optionsHTML;

}

function nextQuestion()
{

let selected =

document.querySelector(
'input[name="answer"]:checked'
);

if(!selected)
{

alert("Please Select An Answer");

return;

}

if(
selected.value ==
quiz[currentQuestion].answer
)
{

score++;

}

currentQuestion++;

if(currentQuestion < quiz.length)
{

loadQuestion();

}
else
{

showResult();

}

}

function showResult()
{

document.getElementById("question").innerHTML =
"Quiz Completed";

document.getElementById("options").innerHTML = "";

document.getElementById("result").innerHTML =

"Your Score: " +

score +

" / " +

quiz.length;

}

loadQuestion();

🎯 Expected Output

Question 1:

Β 
What does HTML stand for?
Β 

User Selects Correct Answer


Question 2:

Β 
Which language is used for styling websites?
Β 

Question 3:

Β 
Which keyword creates a function?
Β 

Final Result:

Β 
Quiz Completed

Your Score: 3 / 3
Β 

🌟 Project Improvements

Add:

βœ… Timer

βœ… Multiple Categories

βœ… Random Questions

βœ… Negative Marking

βœ… Restart Quiz Button

βœ… Quiz Certificate


🏫 Real World Applications

Quiz Applications are used in:

βœ… Online Exams

βœ… LMS Platforms

βœ… School Assessments

βœ… Coding Tests

βœ… Employee Training

βœ… Certification Platforms


⚠️ Common Beginner Mistakes

Mistake 1

Forgetting to call:

loadQuestion();

Quiz will not start.


Mistake 2

Wrong answer comparison.

Always compare:

selected.value

with

quiz[currentQuestion].answer

Mistake 3

Not validating radio selection.

Users may click Next without selecting an answer.


🌟 Best Practices

βœ… Keep questions inside arrays.

βœ… Use objects for question storage.

βœ… Validate user input.

βœ… Keep UI simple.

βœ… Display final score clearly.


πŸ† Project Challenge

Modify the project and add:

βœ… 10 Questions

βœ… Timer

βœ… Restart Quiz Button

βœ… Percentage Calculation

βœ… Pass/Fail Status


πŸ“ Practical Activity

Create:

Computer Fundamentals Quiz

Questions:

  • Input Device
  • Output Device
  • CPU
  • RAM
  • Operating System

Display score at the end.


πŸ“‹ Assignment

Assignment 7.6

  1. What is a Quiz Application?
  2. Why are Arrays used?
  3. What is an Object?
  4. How is score calculated?
  5. Create a Quiz Application.
  6. Add 5 new questions.
  7. Add a Restart Quiz button.

🧠 Quiz

Q1. Which structure stores multiple questions?

A. Variable

B. Array

C. Loop

D. Event

βœ… Answer: B


Q2. Each question is stored as?

A. Function

B. Variable

C. Object

D. Loop

βœ… Answer: C


Q3. Which method selects checked radio button?

A. getElementById()

B. querySelector()

C. createElement()

D. innerHTML

βœ… Answer: B


Q4. Which variable stores correct answers count?

A. currentQuestion

B. answer

C. score

D. result

βœ… Answer: C


Q5. Quiz Application uses?

A. Arrays

B. Objects

C. DOM Manipulation

D. All of These

βœ… Answer: D


πŸ“Œ Lesson Summary

βœ… Built a complete Quiz Application.

βœ… Learned Arrays and Objects.

βœ… Used DOM Manipulation.

βœ… Calculated score dynamically.

βœ… Created a real-world educational project.

Scroll to Top