Question: please rewrite this without using parentElement.classList.add or document.querySelector function loadQuestion ( questionIndex ) { var currentFieldset = document.getElementById ( ' question - ' + questionIndex

please rewrite this without using parentElement.classList.add or document.querySelector
function loadQuestion(questionIndex){
var currentFieldset = document.getElementById('question-'+ questionIndex);
if (!currentFieldset){
window.alert('Invalid question index.');
return;
}
// Hide all fieldsets
var allFieldsets = document.getElementsByTagName('fieldset');
for (var i =0; i < allFieldsets.length; i++){
allFieldsets[i].style.display = 'none';
}
// Show the next question
var nextFieldset = document.getElementById('question-'+ questionIndex);
if (nextFieldset){
nextFieldset.style.display = 'block';
}
// Update progress bar
var progressPercentage =(questionIndex / totalQuestions)*100;
progressBar.style.width = progressPercentage +'%';
// Hide the "Next Question" button until "Check Answer" is clicked
nextQuestionButton.style.display = 'none';
}
function checkAnswer(questionIndex){
var selectedAnswer = null;
var radioButtons = document.getElementsByName('answer-'+ questionIndex);
for (var i =0; i < radioButtons.length; i++){
if (radioButtons[i].checked){
selectedAnswer = radioButtons[i];
break;
}
}
if (!selectedAnswer){
window.alert('Please select an answer.');
return;
}
var correctAnswer = document.getElementById('correct-answer-'+ questionIndex).value;
if (selectedAnswer.value === correctAnswer){
selectedAnswer.parentElement.classList.add('highlight-correct');
correctAnswerCount++; // Increment correct answers count
} else {
selectedAnswer.parentElement.classList.add('highlight-incorrect');
var correctAnswerInput = document.querySelector('input[value="'+ correctAnswer +'"]');
if (correctAnswerInput){
correctAnswerInput.parentElement.classList.add('highlight-correct');
}
}
// Show the "Next Question" button
nextQuestionButton.style.display = 'block';
if (questionIndex === totalQuestions){
displayCompletionMessage(correctAnswerCount); // Use the correctAnswerCount variable directly
}
}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!