Solved a few bugs on the WriteBlanks module

This commit is contained in:
Tiago Ribeiro
2023-09-03 15:06:56 +01:00
parent 5263cc260d
commit 10b2f09c7f
10 changed files with 56 additions and 53 deletions

View File

@@ -10,8 +10,10 @@ type Solution = "true" | "false" | "not_given";
export default function TrueFalseSolution({prompt, type, id, questions, userSolutions, onNext, onBack}: TrueFalseExercise & CommonProps) {
const calculateScore = () => {
const total = questions.length || 0;
const correct = userSolutions.filter((x) => questions.find((y) => x.id === y.id)?.solution === x.solution.toLowerCase() || false).length;
const missing = total - userSolutions.filter((x) => questions.find((y) => x.id === y.id)).length;
const correct = userSolutions.filter(
(x) => questions.find((y) => x.id.toString() === y.id.toString())?.solution === x.solution.toLowerCase() || false,
).length;
const missing = total - userSolutions.filter((x) => questions.find((y) => x.id.toString() === y.id.toString())).length;
return {total, correct, missing};
};
@@ -63,10 +65,10 @@ export default function TrueFalseSolution({prompt, type, id, questions, userSolu
<span className="text-sm w-full leading-6">You can click a selected option again to deselect it.</span>
<div className="bg-mti-gray-smoke rounded-xl px-5 py-6 flex flex-col gap-8">
{questions.map((question, index) => {
const userSolution = userSolutions.find((x) => x.id === question.id);
const userSolution = userSolutions.find((x) => x.id === question.id.toString());
return (
<div key={question.id} className="flex flex-col gap-4">
<div key={question.id.toString()} className="flex flex-col gap-4">
<span>
{index + 1}. {question.prompt}
</span>