π 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
Post a Comment