From 31d4d6f234fc2b1210750b033f499757abe6fbbc Mon Sep 17 00:00:00 2001 From: Oliver Eyton-Williams Date: Thu, 8 Jan 2026 20:04:33 +0100 Subject: [PATCH] feat(tooling): randomize correct answers for multiple choice questions (#65041) --- .../helpers/get-challenge-template.ts | 54 ++++++++----------- 1 file changed, 22 insertions(+), 32 deletions(-) diff --git a/tools/challenge-helper-scripts/helpers/get-challenge-template.ts b/tools/challenge-helper-scripts/helpers/get-challenge-template.ts index f93a579da12..c44c4acf836 100644 --- a/tools/challenge-helper-scripts/helpers/get-challenge-template.ts +++ b/tools/challenge-helper-scripts/helpers/get-challenge-template.ts @@ -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