!DOCTYPE HTML
!DOCTYPE HTML
DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Quiz Website</title>
<style>
body {
font-family: Arial, sans-serif;
margin: 20px;
background-color: #f7f7f7;
}
h1 {
color: #4CAF50;
text-align: center;
}
.question {
margin-bottom: 15px;
padding: 10px;
background: #fff;
border: 1px solid #ddd;
border-radius: 5px;
}
.question p {
font-weight: bold;
}
.result {
margin-top: 20px;
padding: 15px;
border: 2px solid #4CAF50;
background-color: #e8f5e9;
border-radius: 5px;
}
.question-result {
margin-top: 10px;
padding: 10px;
border: 1px solid #ddd;
border-radius: 5px;
background: #fff;
}
.correct {
color: green;
}
.wrong {
color: red;
}
.unattempted {
color: gray;
}
button {
display: block;
margin: 20px auto;
padding: 10px 20px;
font-size: 16px;
color: #fff;
background-color: #4CAF50;
border: none;
border-radius: 5px;
cursor: pointer;
}
button:hover {
background-color: #45a049;
}
</style>
</head>
<body>
<h1>Quiz Website</h1>
<form id="quiz-form">
<div id="questions-container"></div>
<button type="button" onclick="submitQuiz()">Submit Exam</button>
</form>
<script>
const questions = [
{ question: "A very expensive and elaborately built tomb", options:
["Mausoleum", "Cemetery", "Mosque", "Masterpiece"], answer: "Mausoleum" },
{ question: "Holding on to something or keeping an opinion with
determination", options: ["Tenacious", "Obnoxious", "Gracious", "Loquacious"],
answer: "Tenacious" },
{ question: "Evoking a keen sense of sadness or regret", options:
["Unaffecting", "Impactful", "Poignant", "Pungent"], answer: "Poignant" },
// Add all questions in a similar format
];
function renderQuestions() {
const container = document.getElementById('questions-container');
questions.forEach((q, index) => {
const questionDiv = document.createElement('div');
questionDiv.classList.add('question');
q.options.forEach(option => {
const label = document.createElement('label');
const input = document.createElement('input');
input.type = 'radio';
input.name = `q${index}`;
input.value = option;
label.appendChild(input);
label.appendChild(document.createTextNode(option));
questionDiv.appendChild(label);
questionDiv.appendChild(document.createElement('br'));
});
container.appendChild(questionDiv);
});
}
function submitQuiz() {
const answers = {};
const correctAnswers = {};
let correctCount = 0, wrongCount = 0, unattemptedCount = 0;
const detailedResults = document.getElementById('detailed-results');
detailedResults.innerHTML = '';
correctAnswers[`q${index}`] = q.answer;
if (selected) {
answers[`q${index}`] = selected.value;
const userAnswerText = document.createElement('p');
userAnswerText.innerHTML = `Your Answer: <strong>$
{selected.value}</strong>`;
resultDiv.appendChild(userAnswerText);
detailedResults.appendChild(resultDiv);
});
document.getElementById('correct-answers').textContent = `Correct
answers: ${correctCount}`;
document.getElementById('wrong-answers').textContent = `Wrong answers:
${wrongCount}`;
document.getElementById('unattempted-questions').textContent =
`Unattempted questions: ${unattemptedCount}`;
document.getElementById('final-score').textContent = `Final Score: $
{finalScore} points`;
document.getElementById('quiz-form').style.display = 'none';
document.getElementById('result-section').style.display = 'block';
}
</html>