feat(tooling): randomize correct answers for multiple choice questions (#65041)

This commit is contained in:
Oliver Eyton-Williams
2026-01-08 20:04:33 +01:00
committed by GitHub
parent 7f2a1bc6f5
commit 31d4d6f234
@@ -211,7 +211,25 @@ Answer 3
const getMultipleChoiceChallengeTemplate = (
options: ChallengeOptions
): string => `${buildFrontMatter(options)}
): string => {
const correctAnswerIndex = Math.floor(Math.random() * 4) + 1;
const feedback = (index: number) =>
index === correctAnswerIndex
? ''
: `
### --feedback--
Include feedback for answer ${index} here.
`;
const answers = [1, 2, 3, 4]
.map(
index => `Answer ${index}
${feedback(index)}`
)
.join('\n---\n\n');
return `${buildFrontMatter(options)}
# --description--
@@ -225,40 +243,12 @@ ${options.title} question?
## --answers--
Answer 1
### --feedback--
Include feedback for answer 1 here, but remove these last four lines if this is the correct answer.
---
Answer 2
### --feedback--
Include feedback for answer 2 here, but remove these last four lines if this is the correct answer.
---
Answer 3
### --feedback--
Include feedback for answer 3 here, but remove these last four lines if this is the correct answer.
---
Answer 4
### --feedback--
Include feedback for answer 4 here, but remove these last four lines if this is the correct answer.
${answers}
## --video-solution--
1
${correctAnswerIndex}
`;
};
const getFillInTheBlankChallengeTemplate = (
options: ChallengeOptions