How To Make A Quiz App Using HTML CSS and JavaScript

Quizzes have been a popular form of entertainment and knowledge assessment for a long time. With the rise of technology, making a quiz has become even easier and more accessible.

In this blog post, we will guide you on how to make a quiz app using HTML, CSS, and JavaScript. Whether you are a beginner or have some prior knowledge of web development, this tutorial will provide you with step-by-step instructions to create a functioning quiz app.

Get ready to dive into the world of coding and build your first quiz app today. Recently I create a CountDoum timer using JavaScript please check this.

What is Quiz App?

Quiz app HTML CSS JavaScript

A quiz app is a software application that presents a series of questions to the user, usually in a multiple-choice format, with the purpose of testing the user’s knowledge or assessing their skills in a specific subject area.

Quiz apps can be used for educational, entertainment, or competitive purposes, and can be designed for different platforms such as the web, mobile, or desktop.

Quiz apps typically keep track of the user’s answers and score, and may provide feedback or rewards based on the results.

Steps To Create a Quiz App:

  1. Define the purpose and scope of your quiz app: Determine the type of quiz you want to create, what topic it will cover, and what features you want to include.
  2. Plan your quiz structure: Decide on the number of questions you want to include, the format of each question, and how you want to present the answers.
  3. Design the user interface: Decide on the layout and overall look of your quiz app. This includes selecting a color scheme, font, and any images or graphics you want to use.
  4. Create the content: Write the questions and answers for your quiz. Make sure the questions are clear and concise, and that the answers are accurate and relevant.
  5. Test the quiz: Try out your quiz app to make sure it works as expected and to identify any bugs or areas for improvement.
  6. Launch the quiz: Publish your quiz app to a hosting platform or deploy it to a web server so that others can access it.
  7. Promote your quiz: Spread the word about your quiz app by sharing it on social media, posting it on forums, and reaching out to relevant communities.

By following these steps, you can create a functioning quiz app that will engage and challenge your users.

Video Tutorial Quiz App HTML, CSS, and JavaScript

If you are a beginner in coding and programming so please watch this video and subscribe to this YouTube Channel for more videos like this.

Video Created by WS-Cube Tech YouTube Channel

Complete Source Code Quiz App

In this project, I am using three languages first one is HTML for basic structure second language is CSS for design and last is JavaScript for logic.

To Create this type of Quiz App you need to create three files first HTML, Second for CSS, and Last for JavaScript.

HTML FILE CODE

Copy the HTML code and paste it into your file make sure your file extension is (.html).

<!DOCTYPE html>
<!-- Created by Coding Pakistan -->
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link rel="stylesheet" href="style.css" />
</head>
<body>
    <section class="main">
        <div class="container">
            <div class="col">
                <h3 id="questionBox">
                    1) Lorem ipsum dolor sit amet, consectetur adipisicing elit Debitis?
                </h3>
            </div>
            <div class="col box">
                <input name="option" type="radio" id="first" value="a" required>
                <label for="first">Testing 1</label>
            </div>
            <div class="col box">
                <input name="option" type="radio" id="second" value="b" required>
                <label for="second">Testing 2</label>
            </div>
            <div class="col box">
                <input name="option" type="radio" id="third" value="c" required>
                <label for="third">Testing 3</label>
            </div>
            <div class="col box">
                <input name="option" type="radio" id="fourth" value="d" required>
                <label for="fourth">Testing 4</label>
            </div>
            <button id="submit">Submit</button>
        </div>
    </section>
    <script src="script.js"></script>
</body>
</html>

CSS FILE CODE

Copy the CSS code and paste it into your file make sure your file extension is (.css).

/* Created by Coding Pakistan */
* {
    padding: 0;
    margin: 0;
    box-sizing: border-box;
    font-family: 'Poppins', sans-serif;
}
@import url('https://fonts.googleapis.com/css2?family=Poppins:wght@100&display=swap');
.main {
    width: 100%;
    height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    background-color: rgb(24, 128, 207);
}
.container {
    width: 35rem;
    box-shadow: 0px 0px 5px grey;
    display: flex;
    background-color: white;
    border-radius: 10px;
    overflow: hidden;
    flex-direction: column;
}
.col {
    text-align: justify;
    padding: 15px;
    width: 95%;
}
#submit {
    width: 100%;
    background-color: rgb(47, 8, 73);
    transition: 0.5s;
    color: white;
    outline: none;
    border: none;
    font-size: 25px;
    display: block;
    padding: 10px;
    cursor: pointer;
}
#submit:hover {
    background-color: rgb(34, 6, 53);
}
.box {
    box-shadow: 0px -1px 1px grey;
    width: 100%;
}
JAVASCRIPT FILE CODE
Copy the JavaScript code and paste it into your file make sure your file extension is (.js).
// Created by Coding Pakistan
const quizData = [{
    question: "Which of the following is a client site language?",
    a: "Java",
    b: "C",
    c: "Python",
    d: "JavaScript",
    correct: "d",
},
{
    question: "What does HTML stand for?",
    a: "Hypertext Markup Language",
    b: "Cascading Style Sheet",
    c: "Jason Object Notation",
    d: "Helicopters Terminals Motorboats Lamborginis",
    correct: "a",
},
{
    question: "What year was JavaScript launched?",
    a: "1996",
    b: "1995",
    c: "1994",
    d: "none of the above",
    correct: "b",
},
{
    question: "What does CSS stands for?",
    a: "Hypertext Markup Language",
    b: "Cascading Style Sheet",
    c: "Jason Object Notation",
    d: "Helicopters Terminals Motorboats Lamborginis",
    correct: "b",
}
];
let index = 0;
let correct = 0,
incorrect = 0,
total = quizData.length;
let questionBox = document.getElementById("questionBox");
let allInputs = document.querySelectorAll("input[type='radio']")
const loadQuestion = () => {
if (total === index) {
    return quizEnd()
}
reset()
const data = quizData[index]
questionBox.innerHTML = `${index + 1}) ${data.question}`
allInputs[0].nextElementSibling.innerText = data.a
allInputs[1].nextElementSibling.innerText = data.b
allInputs[2].nextElementSibling.innerText = data.c
allInputs[3].nextElementSibling.innerText = data.d
}
document.querySelector("#submit").addEventListener(
"click",
function() {
    const data = quizData[index]
    const ans = getAnswer()
    if (ans === data.correct) {
        correct++;
    } else {
        incorrect++;
    }
    index++;
    loadQuestion()
}
)
const getAnswer = () => {
let ans;
allInputs.forEach(
    (inputEl) => {
        if (inputEl.checked) {
            ans = inputEl.value;
        }
    }
)
return ans;
}
const reset = () => {
allInputs.forEach(
    (inputEl) => {
        inputEl.checked = false;
    }
)
}
const quizEnd = () => {
// console.log(document.getElementsByClassName("container"));
document.getElementsByClassName("container")[0].innerHTML = `
    <div class="col">
        <h3 class="w-100"> Hii, you've scored ${correct} / ${total} </h3>
    </div>
}
loadQuestion(index);

After that, your Quiz app is ready to use if you want to preview this App so Click this Quiz App Preview link.

You Might Like This

Conclusion

Making a quiz app using HTML, CSS, and JavaScript is a fun and educational process that can help you understand how to build dynamic web pages. To create a quiz app, you need to have basic knowledge of HTML for structure, CSS for styling, and JavaScript for functionality.

You can start by creating a simple multiple-choice quiz and gradually add more complexity as you improve your skills. With the right tools and resources, you can easily turn your ideas into a functional and engaging quiz app

Leave a Comment