Skip to content

Commit

Permalink
Fix: Allow case-insensitive checks for array of accepted item answers (
Browse files Browse the repository at this point in the history
…fixes #153)

* Fix: Allow case-insensitive checks for array of accepted item answers

* Simplified correctness approach

* Renamed function
  • Loading branch information
cahirodoherty-learningpool authored Nov 18, 2024
1 parent e01e6e0 commit cfeb61e
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions js/textInputModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,12 +150,13 @@ class TextInputModel extends QuestionModel {
this.get('_items').forEach(item => {
const hasItemAnswers = Boolean(item._answers?.length);
if (!hasItemAnswers) return;
const answers = item._answers;

const answers = item._answers.map(answer => this.cleanupAnswer(answer));
const userAnswer = item.userAnswer || '';
const isCorrect = this.checkAnswerIsCorrect(answers, userAnswer);
item._isCorrect = isCorrect;
item._answerIndex = answers.indexOf(this.cleanupUserAnswer(userAnswer));
if (!isCorrect) return;
item._answerIndex = answers.indexOf(this.cleanupAnswer(userAnswer));
item._isCorrect = (item._answerIndex !== -1);
if (!item._isCorrect) return;

this.set({
_numberOfCorrectAnswers: ++numberOfCorrectAnswers,
_isAtLeastOneCorrectSelection: true
Expand All @@ -164,15 +165,14 @@ class TextInputModel extends QuestionModel {
}

checkAnswerIsCorrect(possibleAnswers, userAnswer) {
const uAnswer = this.cleanupUserAnswer(userAnswer);
const uAnswer = this.cleanupAnswer(userAnswer);

const answerIsCorrect = possibleAnswers.some(cAnswer => {
return this.cleanupUserAnswer(cAnswer) === uAnswer;
return possibleAnswers.some(cAnswer => {
return this.cleanupAnswer(cAnswer) === uAnswer;
});
return answerIsCorrect;
}

cleanupUserAnswer(userAnswer) {
cleanupAnswer(userAnswer) {
if (this.get('_allowsAnyCase')) {
userAnswer = userAnswer.toLowerCase();
}
Expand Down

0 comments on commit cfeb61e

Please sign in to comment.