Hi @Maui Learner
To check the answer based on the answer index, first, you should according to the question index to find all answers and then find the correct answer index, after that compare it with the Questions[questionIndex].Correct.
So, you can modify the condition statement as below:
protected void OptionSelected(string option)
{
//check the answer based on text.
//if (option.Trim() == Questions[questionIndex].Answer.Trim())
//check the answer based on answer index.
// var anserindex = Questions[questionIndex].Options.ToList().IndexOf(option.Trim()) + 1; //: find the answer index from the options,
// var correctindex = Questions[questionIndex].Correct; // get the correct answer from the Questions
if ((Questions[questionIndex].Options.ToList().IndexOf(option.Trim()) + 1) == Questions[questionIndex].Correct)
{
score++;
}
else
{
failedQuestions[failedIndex] = Questions[questionIndex].QuestionTitle + " " + Questions[questionIndex].Answer;
failedIndex++;
}
questionIndex++;
}
After that, the result like this:
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.
Best regards,
Dillion