Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

=+c) What were the treatments? Chapter Exercises

Answered: 1 week ago

Question

What should be included in the initial can report to FireCom

Answered: 1 week ago

Question

5. Understand how cultural values influence conflict behavior.

Answered: 1 week ago

Question

8. Explain the relationship between communication and context.

Answered: 1 week ago