πŸ“ Build a Quiz App using HTML, CSS & JavaScript

πŸ“ Build a Quiz App using HTML, CSS & JavaScript

Hello everyone πŸ‘‹
Welcome back!

In this beginner-friendly project, we will build a Quiz App using HTML, CSS & JavaScript πŸ’»

This project helps you learn:

- DOM Manipulation
- JavaScript Logic
- Event Handling
- Score Calculation

Perfect for beginners πŸš€

---

🌟 Features of Quiz App

✔ Multiple Questions
✔ Score Counter
✔ Next Question Button
✔ Result Display
✔ Responsive Design
✔ Beginner-friendly UI

---

🧱 Step 1: HTML Code

HTML

<!DOCTYPE html>
<html>
<head>
    <title>Quiz App</title>
    <link rel="stylesheet" href="style.css">
</head>
<body>

<div class="quiz-container">

    <h1>Quiz App</h1>

    <div id="question">Question Here</div>

    <div id="answers"></div>

    <button id="nextBtn">Next</button>

</div>

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

---

🎨 Step 2: CSS Code

CSS

*{
    margin:0;
    padding:0;
    box-sizing:border-box;
    font-family:Arial;
}

body{
    height:100vh;
    display:flex;
    justify-content:center;
    align-items:center;
    background:linear-gradient(135deg,#667eea,#764ba2);
}

.quiz-container{
    background:white;
    padding:30px;
    width:400px;
    border-radius:15px;
    box-shadow:0 10px 25px rgba(0,0,0,0.2);
}

h1{
    margin-bottom:20px;
    text-align:center;
}

#question{
    font-size:20px;
    margin-bottom:20px;
}

button{
    width:100%;
    padding:12px;
    margin-top:10px;
    border:none;
    border-radius:8px;
    background:#007bff;
    color:white;
    cursor:pointer;
}

---

⚡ Step 3: JavaScript Code

JavaScript

const questions = [

{
    question:"What does HTML stand for?",
    answers:["Hyper Text Markup Language",
             "High Text Machine Language",
             "Hyper Tool Multi Language"],
    correct:0
},

{
    question:"Which language is used for styling?",
    answers:["HTML","CSS","Python"],
    correct:1
}

];

let currentQuestion = 0;
let score = 0;

const questionEl =
document.getElementById("question");

const answersEl =
document.getElementById("answers");

const nextBtn =
document.getElementById("nextBtn");

function loadQuestion(){

    const q = questions[currentQuestion];

    questionEl.textContent = q.question;

    answersEl.innerHTML = "";

    q.answers.forEach((answer,index)=>{

        const btn =
        document.createElement("button");

        btn.textContent = answer;

        btn.onclick = () => checkAnswer(index);

        answersEl.appendChild(btn);
    });
}

function checkAnswer(index){

    if(index === questions[currentQuestion].correct){
        score++;
    }

    nextBtn.style.display = "block";
}

nextBtn.onclick = () => {

    currentQuestion++;

    if(currentQuestion < questions.length){
        loadQuestion();
    }else{
        questionEl.textContent =
        `Quiz Finished! Score: ${score}`;

        answersEl.innerHTML = "";
        nextBtn.style.display = "none";
    }
};

loadQuestion();

---

🎯 What You Will Learn

✅ DOM Manipulation
✅ Event Handling
✅ Dynamic Question System
✅ JavaScript Logic Building
✅ Score Calculation

---

⭐ Tips to Improve Project

πŸ‘‰ Add timer ⏱️
πŸ‘‰ Add more questions πŸ“š
πŸ‘‰ Add dark mode πŸŒ™
πŸ‘‰ Store high scores πŸ’Ύ

---

πŸ“Œ Conclusion

This was a Quiz App Project using JavaScript πŸ“

A perfect beginner project to improve your JavaScript and frontend development skills πŸš€

---

πŸ“’ Also Read

πŸ‘‰ Weather App Project
πŸ‘‰ To-Do App Project
πŸ‘‰ JavaScript Interview Guide

---

πŸ‘‰ Save and share this project πŸ“Œ
πŸ‘‰ Follow for more coding content πŸ’»

Comments

Popular posts from this blog

Build a Simple Calculator using HTML, CSS & JavaScript (Beginner Project)

Top 10 Python Programs for Beginners (Easy + Practical Guide)

JavaScript Notes for Beginners (Simple + Easy Guide) ⚡