diff --git a/components/MdxContent.tsx b/components/MdxContent.tsx index 19605dc..9dcf1ea 100644 --- a/components/MdxContent.tsx +++ b/components/MdxContent.tsx @@ -43,14 +43,14 @@ export const MdxContent = ({content, chapterId, bookId, t, allAnswers}: { longtext, points, trials, id, question, ...restProps } = props; - const actAnswer = + const correctAnswer = (answer || options ?.find((opt) => opt.startsWith(CorrectAnswerPrefix)) ?.slice(CorrectAnswerPrefix.length) || undefined) - ?.trim() - .toLowerCase() + ?.trim(); + const actAnswer = correctAnswer?.toLowerCase() const actOptions = options?.map( (opt) => opt.startsWith(CorrectAnswerPrefix) @@ -76,6 +76,7 @@ export const MdxContent = ({content, chapterId, bookId, t, allAnswers}: { bookId={bookId!} type={type} scorer={actScorer} + correctAnswer={correctAnswer} options={actOptions} maxPoints={ungraded ? 0 : (points ?? 1)} maxTrials={trials ?? 1} diff --git a/components/Quiz/Quiz.tsx b/components/Quiz/Quiz.tsx index 2db2e70..48876a1 100644 --- a/components/Quiz/Quiz.tsx +++ b/components/Quiz/Quiz.tsx @@ -19,6 +19,7 @@ export interface IQuestion extends QuizPropsBase { id: string; type: QuestionTypes; scorer: (option: string) => (boolean | undefined) + correctAnswer?: string; bookId: number; maxPoints: number; maxTrials: number; @@ -39,6 +40,7 @@ export default function Question({ question, options = [], checker, + correctAnswer, scorer, maxPoints = 0, maxTrials = 1, @@ -102,6 +104,11 @@ export default function Question({ if (trials < maxTrials && maxTrials > 1) { msg += ` ${t("quiz.remaining")}: ${maxTrials - trials}` } + else { + if (maxTrials > 0 && correctAnswer) { + msg += ` ${t("quiz.correct-answer")} "${correctAnswer}"`; + } + } return msg; } case true: { @@ -114,7 +121,7 @@ export default function Question({ default: return null; } - }, [t, submissionErrored, isCorrect, trials, maxTrials, points]); + }, [t, submissionErrored, isCorrect, correctAnswer, trials, maxTrials, points]); const correctnessClass = React.useMemo(() => { if (submissionErrored) { diff --git a/i18n/dict.tsx b/i18n/dict.tsx index 1420a02..b2f1786 100644 --- a/i18n/dict.tsx +++ b/i18n/dict.tsx @@ -47,6 +47,7 @@ const dict: {[lang: string]: {[key: string]: any}} = { "quiz-progress.remaining": (n: number) => `\n${n} ${pl(n, "question")} remaining.`, "quiz.submit-button": "Submit", "quiz.incorrect": "Your answer is incorrect.", + "quiz.correct-answer": "Correct answer:", "quiz.attempts": "Allowed attempts", "quiz.remaining": "Remaining attempts", "quiz.correct": "Correct!", @@ -125,6 +126,7 @@ const dict: {[lang: string]: {[key: string]: any}} = { `\n${plsi(n, `Ostalo je še eno vprašanje|Ostali sta še dve vprašanji|Ostala so še ${n} vprašanja|Ostalo je še ${n} vprašanj`)}.`, "quiz.submit-button": "Oddaj", "quiz.incorrect": "Odgovor ni pravilen.", + "quiz.correct-answer": "Pravilen odgovor:", "quiz.attempts": "Možnih poskusov", "quiz.remaining": "Preostalih poskusov", "quiz.correct": "Pravilno!",