From 16d333adb933c9a23b9ce660dc5b0a95c6479355 Mon Sep 17 00:00:00 2001 From: samad13 Date: Tue, 27 Jan 2026 14:55:57 +0100 Subject: [PATCH 1/2] Implement-Answer-Validation-and-Feedback-System --- frontend/app/quiz/page.tsx | 61 +++++++++++++++++------ frontend/components/quiz/AnswerOption.tsx | 8 +-- frontend/lib/Quiz_data.ts | 6 ++- 3 files changed, 55 insertions(+), 20 deletions(-) diff --git a/frontend/app/quiz/page.tsx b/frontend/app/quiz/page.tsx index 1f78332..20d6e78 100644 --- a/frontend/app/quiz/page.tsx +++ b/frontend/app/quiz/page.tsx @@ -21,7 +21,8 @@ export default function QuizPage() { const actionBtnRef = useRef(null); - const question = MOCK_QUIZ[step]; + const QUIZ = MOCK_QUIZ.slice(0, 2); + const question = QUIZ[step]; const handleSelectOption = (optionId: string) => { if (isSubmitted) return; @@ -36,15 +37,17 @@ export default function QuizPage() { const handleAction = () => { if (!isSubmitted) { - setIsSubmitted(true); - const selectedOption = question.options.find( - (opt) => opt.id === selectedId, - ); - if (selectedOption?.isCorrect) { - setScore((prev) => prev + 1); - } + setTimeout(() => { + setIsSubmitted(true); + const selectedOption = question.options.find( + (opt) => opt.id === selectedId, + ); + if (selectedOption?.isCorrect) { + setScore((prev) => prev + 1); + } + }, 150); } else { - if (step < MOCK_QUIZ.length - 1) { + if (step < QUIZ.length - 1) { setStep(step + 1); setSelectedId(null); setIsSubmitted(false); @@ -58,16 +61,14 @@ export default function QuizPage() {
- {!isFinished && ( - - )} + {!isFinished && }
{isFinished ? ( alert("Points Claimed!")} /> @@ -76,6 +77,9 @@ export default function QuizPage() {

{question.question}

+

+ Points: {score * 10} +

{question.options.map((opt) => { const isSelected = selectedId === opt.id; @@ -83,9 +87,9 @@ export default function QuizPage() { if (isSubmitted) { if (isSelected) { - state = opt.isCorrect ? "green" : "red"; + state = opt.isCorrect ? "teal" : "red"; } else if (opt.isCorrect) { - state = "green"; + state = "teal"; } } else if (isSelected) { state = "teal"; @@ -102,6 +106,33 @@ export default function QuizPage() { ); })}
+ {isSubmitted && ( +
+ {(() => { + const selectedOption = question.options.find( + (o) => o.id === selectedId, + ); + const correctOption = question.options.find( + (o) => o.isCorrect, + ); + const wasCorrect = !!selectedOption?.isCorrect; + return ( + <> + {!wasCorrect && correctOption && ( +
+ Correct answer: {correctOption.text} +
+ )} + {question.explanation && ( +

+ {question.explanation} +

+ )} + + ); + })()} +
+ )}