Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions components/MdxContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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}
Expand Down
9 changes: 8 additions & 1 deletion components/Quiz/Quiz.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -39,6 +40,7 @@ export default function Question({
question,
options = [],
checker,
correctAnswer,
scorer,
maxPoints = 0,
maxTrials = 1,
Expand Down Expand Up @@ -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: {
Expand All @@ -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) {
Expand Down
2 changes: 2 additions & 0 deletions i18n/dict.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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!",
Expand Down Expand Up @@ -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!",
Expand Down