Practice Questions for NET JRF Group Theory Assignment: Conjugate Classes and Class Equation
« Previous
Next »
const feedbackList = document.querySelectorAll('.feedback');
const explanationList = document.querySelectorAll('.explanation');
function checkAnswer(questionIndex) {
const options = document.querySelectorAll(`.question:nth-child(${questionIndex + 1}) .options input:checked`);
const feedback = feedbackList[questionIndex];
const explanation = explanationList[questionIndex];
if (options.length === 0) {
feedback.innerHTML = `Question not attempted. The correct answer is ${formatCorrectAnswer(correctAnswers[questionIndex])}.`;
feedback.className = 'not-attempted';
} else if (compareArrays(Array.from(options).map(option => option.value), correctAnswers[questionIndex])) {
feedback.innerHTML = 'Correct answer!';
feedback.className = 'correct';
} else {
feedback.innerHTML = `Incorrect answer. The correct answer is ${formatCorrectAnswer(correctAnswers[questionIndex])}.`;
feedback.className = 'incorrect';
}
explanation.style.display = 'block';
}
document.querySelectorAll('.submit-button').forEach((submitButton, index) => {
submitButton.addEventListener('click', () => {
checkAnswer(index);
});
});
function compareArrays(arr1, arr2) {
return arr1.length === arr2.length && arr1.every(value => arr2.includes(value));
}
function formatCorrectAnswer(answer) {
if (Array.isArray(answer)) {
return answer.join(', ');
}
return answer;
}
0 Comments