multiple_choice questions shows incorrect result even if correct options selected.

Created on 6 September 2023, 10 months ago
Updated 29 October 2023, 8 months ago

Problem/Motivation

hi, so the issue that i am facing is related to multiple_choice questions. Lets say there is a multiple_choice question with 3 correct options, so if the user selects the correct options out of order such as first he selects the third correct option, then second and then first, then if he submits the quiz, he will then get incorrect result even though he selected all the correct options, now, if he submit the quiz again with correct options, selected in correct order, then he get the correct result.

I have inspected the code, and the reason why this happens is because in the following file line 272:

Drupal\anu_lms_assessments\Plugin\rest\resource\QuestionRestResource

the arrays of both $expected_answer & $provided_answers are compared directly like this:

      if ($expected_answer == $provided_answers) {
        $question_result->set('is_correct', AssessmentQuestionResult::RESULT_CORRECT);
        $is_correct_answer = TRUE;
      }
      else {
        $question_result->set('is_correct', AssessmentQuestionResult::RESULT_INCORRECT);
      }

so even if both arrays contain the same elements but if their order is not same, the condition results in false and hence we get incorrect result, i am attaching a patch which will sort both arrays before comparing them hence it will take care of this issue.

Steps to reproduce

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

πŸ› Bug report
Status

Fixed

Version

2.0

Component

Code

Created by

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.69.0 2024