Answered step by step
Verified Expert Solution
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 loadQuestionquestionIndex
var currentFieldset document.getElementByIdquestion questionIndex;
if currentFieldset
window.alertInvalid question index.;
return;
Hide all fieldsets
var allFieldsets document.getElementsByTagNamefieldset;
for var i ; i allFieldsets.length; i
allFieldsetsistyle.display 'none';
Show the next question
var nextFieldset document.getElementByIdquestion questionIndex;
if nextFieldset
nextFieldset.style.display 'block';
Update progress bar
var progressPercentage questionIndex totalQuestions;
progressBar.style.width progressPercentage ;
Hide the "Next Question" button until "Check Answer" is clicked
nextQuestionButton.style.display 'none';
function checkAnswerquestionIndex
var selectedAnswer null;
var radioButtons document.getElementsByNameanswer questionIndex;
for var i ; i radioButtons.length; i
if radioButtonsichecked
selectedAnswer radioButtonsi;
break;
if selectedAnswer
window.alertPlease select an answer.;
return;
var correctAnswer document.getElementByIdcorrectanswer questionIndexvalue;
if selectedAnswervalue correctAnswer
selectedAnswer.parentElement.classList.addhighlightcorrect';
correctAnswerCount; Increment correct answers count
else
selectedAnswer.parentElement.classList.addhighlightincorrect';
var correctAnswerInput document.querySelectorinputvalue correctAnswer ;
if correctAnswerInput
correctAnswerInput.parentElement.classList.addhighlightcorrect';
Show the "Next Question" button
nextQuestionButton.style.display 'block';
if questionIndex totalQuestions
displayCompletionMessagecorrectAnswerCount; Use the correctAnswerCount variable directly
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started