Skip to content

Commit

Permalink
Merge pull request anuragverma108#2691 from Vin205/main
Browse files Browse the repository at this point in the history
Added Quiz
  • Loading branch information
huamanraj authored Jul 30, 2024
2 parents 9b8acba + 3f5f845 commit 8297841
Show file tree
Hide file tree
Showing 4 changed files with 160 additions and 1 deletion.
156 changes: 156 additions & 0 deletions assets/html/quiz.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Interactive Quiz</title>
<style>
body {
font-family: Arial, sans-serif;
margin: 0;
padding: 20px;
background-color: rgba(244, 197, 202, 0.9);
background-size: cover;
}
.quiz-container {
max-width: 600px;
margin: auto;
background: rgba(251, 224, 243, 0.9);
padding: 20px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
}
.question {
font-size: 18px;
margin-bottom: 10px;
}
.answers {
list-style-type: none;
padding: 0;
}
.answers li {
margin-bottom: 10px;
}
button {
display: block;
width: 100%;
padding: 10px;
background: #7a0101;
color: white;
border: none;
font-size: 16px;
cursor: pointer;
}
button:hover {
background: #ee0b1b;
}
.result {
font-size: 18px;
margin-top: 20px;
text-align: center;
}
</style>
</head>
<body>
<br>
<br>
<br>
<br>
<br>
<br>
<div class="quiz-container">
<h1 style="color: maroon;">Test Your Knowledge</h1>
<div id="quiz">
<div class="question" id="question"></div>
<ul class="answers" id="answers"></ul>
<button id="submit">Submit Answer</button>
<div class="result" id="result"></div>
</div>
</div>

<script>
const quizData = [
{
question: "Which genre is known for imaginative and futuristic themes?",
answers: ["Mystery", "Romance", "Science Fiction", "Historical Fiction"],
correct: "Science Fiction"
},
{
question: "Who wrote the famous novel '1984'?",
answers: ["Aldous Huxley", "George Orwell", "Ray Bradbury", "J.R.R. Tolkien"],
correct: "George Orwell"
},
{
question: "Which platform is best known for self-publishing e-books?",
answers: ["Goodreads", "Kindle Direct Publishing", "Wattpad", "Scribd"],
correct: "Kindle Direct Publishing"
},
{
question: "What is the main benefit of an online book exchange platform?",
answers: ["Access to rare books", "Free book swaps", "Connecting with authors", "Personalized book recommendations"],
correct: "Free book swaps"
},
{
question: "Which author is famous for the 'Harry Potter' series?",
answers: ["J.K. Rowling", "C.S. Lewis", "Suzanne Collins", "Rick Riordan"],
correct: "J.K. Rowling"
},
{
question: "What feature allows readers to leave comments and reviews on books they’ve read?",
answers: ["Bookmarking", "Highlighting", "Rating system", "Discussion forums"],
correct: "Discussion forums"
}
];

let currentQuiz = 0;
let score = 0;

const questionElement = document.getElementById('question');
const answersElement = document.getElementById('answers');
const submitButton = document.getElementById('submit');
const resultElement = document.getElementById('result');

function loadQuiz() {
deselectAnswers();
const currentQuizData = quizData[currentQuiz];
questionElement.innerText = currentQuizData.question;
answersElement.innerHTML = '';
currentQuizData.answers.forEach(answer => {
const answerElement = document.createElement('li');
answerElement.innerHTML = `<input type="radio" name="answer" value="${answer}"> ${answer}`;
answersElement.appendChild(answerElement);
});
}

function deselectAnswers() {
document.querySelectorAll('input[name="answer"]').forEach(input => input.checked = false);
}

function getSelected() {
let answer;
document.querySelectorAll('input[name="answer"]').forEach(input => {
if (input.checked) {
answer = input.value;
}
});
return answer;
}

submitButton.addEventListener('click', () => {
const answer = getSelected();
if (answer) {
if (answer === quizData[currentQuiz].correct) {
score++;
}
currentQuiz++;
if (currentQuiz < quizData.length) {
loadQuiz();
} else {
resultElement.innerHTML = `You answered correctly ${score}/${quizData.length} questions.`;
}
}
});

loadQuiz();
</script>
</body>
</html>
2 changes: 1 addition & 1 deletion assets/html/school.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Donate Books to Library</title>
<title>Donate Books to School</title>
<style>
body {
font-family: Arial, sans-serif;
Expand Down
3 changes: 3 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -1163,6 +1163,9 @@
<li class="dropdown-menu-item">
<a href="./assets/html/ConnReader.html" class="navbar-link" data-nav-link><i class="ri-price-tag-3-fill"></i>Reader Connection</a>
</li>
<li class="dropdown-menu-item">
<a href="./assets/html/quiz.html" class="navbar-link">Quizes</a>
</li>
<li class="dropdown-menu-item">
<a href="./assets/html/about.html" class="navbar-link">About</a>
</li>
Expand Down
Binary file added quiz.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 8297841

Please sign in to comment.