Skip to content

Commit

Permalink
Merge pull request #4799 from KapuluruBhuvaneswariVspdbct/main
Browse files Browse the repository at this point in the history
solved #4796 Added solution to midnight children book
  • Loading branch information
sailaja-adapa authored Nov 9, 2024
2 parents 255559c + 9325163 commit ed6736a
Showing 1 changed file with 41 additions and 2 deletions.
43 changes: 41 additions & 2 deletions assets/html/midnight.html
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@
.option {
margin: 5px 0; /* Space between options */
}

.solution {
margin-top: 10px;
text-align: left;
}

</style>
</head>
<body>
Expand All @@ -59,6 +65,7 @@ <h1>Midnight's Children Quiz</h1>
<button id="submit-button" onclick="submitQuiz()">Submit</button>
<div id="quiz-result" style="display: none;"></div>
<button id="home-button" style="display: none;" onclick="window.location.href='index.html';">Return to Home</button>
<button id="solutions-button" style="display: none;" onclick="showSolutions()">See Solutions</button>
</div>

<script>
Expand Down Expand Up @@ -128,12 +135,44 @@ <h1>Midnight's Children Quiz</h1>
function showResult() {
const quizContainer = document.querySelector('.quiz-container');
quizContainer.innerHTML = `<h2>Your Score: ${score}/${quizData.length}</h2>`;

// Create the return home button
const homeButton = document.createElement('button');
homeButton.onclick = () => window.location.href = 'quizzes.html';
homeButton.innerText = 'Return to Quizzes';
quizContainer.appendChild(homeButton);

// Create the see solutions button
const solutionsButton = document.createElement('button');
solutionsButton.onclick = showSolutions;
solutionsButton.innerText = 'See Solutions';
quizContainer.appendChild(solutionsButton);
}

function showSolutions() {
const quizContainer = document.querySelector('.quiz-container');
quizContainer.innerHTML = '<h2>Quiz Solutions</h2>';

quizData.forEach((question, index) => {
const solutionElement = document.createElement('div');
solutionElement.classList.add('solution');

const questionText = document.createElement('h4');
questionText.innerText = `${index + 1}. ${question.question}`;
solutionElement.appendChild(questionText);

const correctAnswer = document.createElement('p');
correctAnswer.innerText = `Correct Answer: ${question.answer}`;
solutionElement.appendChild(correctAnswer);

quizContainer.appendChild(solutionElement);
});

// Add the return to home button again
const homeButton = document.createElement('button');
homeButton.onclick = () => window.location.href = 'quizzes.html';
homeButton.innerText = 'Return to Home';
quizContainer.appendChild(homeButton);
}

function submitQuiz() {
Expand All @@ -149,4 +188,4 @@ <h1>Midnight's Children Quiz</h1>
</script>

</body>
</html>
</html>

0 comments on commit ed6736a

Please sign in to comment.