Skip to content

Commit 3531b7e

Browse files
Merge pull request #39 from ankitjhagithub21/new_branch
added quiz-app
2 parents c3d2eb7 + 4585c02 commit 3531b7e

4 files changed

Lines changed: 147 additions & 0 deletions

File tree

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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">
6+
<title>Quiz App</title>
7+
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-T3c6CoIi6uLrA9TneNEoa7RxnatzjcDSCmG1MXxSR1GAsXEV/Dwwykc2MPK8M2HN" crossorigin="anonymous">
8+
<link rel="stylesheet" href="style.css">
9+
</head>
10+
<body>
11+
<div class="container">
12+
<div class="row px-2">
13+
14+
<div class="col-lg-6 mx-auto text-center shadow rounded p-3" id="quiz-container">
15+
<h2 class="text-success">Quiz App</h2>
16+
<hr>
17+
<h2 id="question" class="fs-4">Question</h2>
18+
<div id="options" class="d-flex flex-column gap-3 my-3">
19+
<button class="btn btn-primary">Option 1</button>
20+
<button class="btn btn-primary">Option 2</button>
21+
<button class="btn btn-primary">Option 3</button>
22+
<button class="btn btn-primary">Option 4</button>
23+
</div>
24+
<button class="btn btn-success" id="next-btn" disabled>Next</button>
25+
</div>
26+
</div>
27+
</div>
28+
29+
<script src="script.js"></script>
30+
</body>
31+
</html>
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Quiz App
2+
3+
This is a simple quiz application built using HTML, CSS, Bootstrap, and JavaScript. It allows users to take quizzes on various topics, select answers, and see their scores at the end of the quiz.
4+
5+
![image](https://github.com/ankitjhagithub21/Web-Devlopment-Projects/assets/91364014/2f07d97e-06b0-4faa-9788-b7365679257a)
6+
7+
8+
## Features
9+
10+
- Multiple-choice questions
11+
- Score tracking
12+
- User-friendly interface
13+
- Responsive design
14+
15+
## Technologies Used
16+
17+
- HTML
18+
- CSS
19+
- Bootstrap
20+
- JavaScript
21+
22+
## Live On
23+
('''https://quiz-app-23.netlify.app/''')
24+
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
const questions = [
2+
{
3+
question: "What is the capital of France?",
4+
options: ["London", "Berlin", "Paris", "Madrid"],
5+
answer: "Paris"
6+
},
7+
{
8+
question: "Which programming language is known for its use in web development?",
9+
options: ["Java", "Python", "JavaScript", "C++"],
10+
answer: "JavaScript"
11+
},
12+
{
13+
question: "What is the result of 2 + 2?",
14+
options: ["3", "4", "5", "6"],
15+
answer: "4"
16+
},
17+
{
18+
question: "What does HTML stand for?",
19+
options: ["Hyper Text Markup Language", "High-Level Text Machine Language", "Hyperlink and Text Markup Language", "Home Tool Markup Language"],
20+
answer: "Hyper Text Markup Language"
21+
}
22+
];
23+
24+
25+
const nextBtn = document.getElementById('next-btn')
26+
const quizContainer = document.getElementById('quiz-container')
27+
const options = document.getElementById('options').querySelectorAll('.btn');
28+
const question = document.getElementById('question')
29+
let score = 0;
30+
let index = 0;
31+
let answer;
32+
33+
34+
const loadQuestion = () => {
35+
nextBtn.setAttribute('disabled','true')
36+
if (index > 0) {
37+
resetAnswer()
38+
}
39+
question.innerHTML = `${index + 1}. ${questions[index].question}`
40+
options.forEach((option, i) => {
41+
option.textContent = questions[index].options[i];
42+
option.addEventListener('click', () => {
43+
44+
nextBtn.removeAttribute('disabled')
45+
resetAnswer()
46+
option.classList.replace('btn-primary', 'btn-dark')
47+
answer = option.textContent
48+
})
49+
})
50+
}
51+
52+
nextBtn.addEventListener('click', () => {
53+
54+
checkAnswer()
55+
index++;
56+
if (index < questions.length) {
57+
loadQuestion()
58+
} else {
59+
endQuiz()
60+
}
61+
62+
})
63+
64+
const endQuiz = () => {
65+
quizContainer.innerHTML = `
66+
<h1>Your Score is ${score}/${questions.length}.</h1>
67+
<button class="btn btn-success mt-3" onclick="window.location.reload()">Play Again</button>
68+
`
69+
}
70+
71+
const checkAnswer = () => {
72+
if (answer == questions[index].answer) {
73+
score++;
74+
}
75+
76+
}
77+
78+
const resetAnswer = () => {
79+
options.forEach((option) => {
80+
if (option.classList.contains('btn-dark')) {
81+
option.classList.replace('btn-dark', 'btn-primary')
82+
}
83+
})
84+
85+
}
86+
loadQuestion()
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
body{
2+
min-height: 100vh;
3+
display: flex;
4+
align-items: center;
5+
justify-content: center;
6+
}

0 commit comments

Comments
 (0)