body {
font-family: Arial, sans-serif;
}
.quiz-container {
max-width: 800px;
margin: 0 auto;
padding: 20px;
border: 1px solid #ccc;
border-radius: 5px;
}
.question {
font-weight: bold;
margin-bottom: 10px;
}
.option {
margin: 5px 0;
padding: 10px;
border: 1px solid #ccc;
border-radius: 5px;
cursor: pointer;
}
.option:not(.selected):hover {
background-color: #f0f0f0;
}
.selected {
background-color: #007acc;
color: white;
}
.correct {
background-color: green;
color: white;
}
.wrong {
background-color: red;
color: white;
}
.explanation {
margin-top: 10px;
display: none;
}
.report-card {
margin-top: 20px;
padding: 10px;
border: 1px solid #ccc;
border-radius: 5px;
background-color: #f0f0f0;
}
.report-card h2{
margin: 0px!important;
}
.report-card p{
margin: 0.5em 0!important;
}
Report Card
Total Questions Attempted: 0
Correct Answers: 0
Wrong Answers: 0
Percentage: 0%
const options = document.querySelectorAll(‘.option’);
const attemptedCount = document.getElementById(‘attemptedCount’);
const correctCount = document.getElementById(‘correctCount’);
const wrongCount = document.getElementById(‘wrongCount’);
const percentage = document.getElementById(‘percentage’);
let totalQuestions = 0;
let correctAnswers = 0;
const attemptedQuestions = new Set();
options.forEach(option => {
option.addEventListener(‘click’, () => {
const questionId = option.getAttribute(‘data-question’);
const isCorrect = option.getAttribute(‘data-correct’) === ‘true’;
if (!attemptedQuestions.has(questionId)) {
options.forEach(o => {
if (o.getAttribute(‘data-question’) === questionId) {
o.classList.remove(‘selected’, ‘correct’, ‘wrong’);
if (o === option) {
o.classList.add(‘selected’);
if (isCorrect) {
o.classList.add(‘correct’);
correctAnswers++;
} else {
o.classList.add(‘wrong’);
options.forEach(correctOption => {
if (
correctOption.getAttribute(‘data-question’) === questionId &&
correctOption.getAttribute(‘data-correct’) === ‘true’
) {
correctOption.classList.add(‘correct’);
}
});
}
totalQuestions++;
attemptedQuestions.add(questionId);
}
}
});
}
// Show explanation
const explanation = document.querySelector(`.explanation[data-question=”${questionId}`);
if (explanation) {
explanation.style.display = ‘block’;
}
attemptedCount.textContent = totalQuestions;
correctCount.textContent = correctAnswers;
wrongCount.textContent = totalQuestions – correctAnswers;
percentage.textContent = ((correctAnswers / totalQuestions) * 100).toFixed(2) + ‘%’;
});
});
