diff --git a/components/QuizCreator.tsx b/components/QuizCreator.tsx index 3fef670..3018663 100644 --- a/components/QuizCreator.tsx +++ b/components/QuizCreator.tsx @@ -14,6 +14,7 @@ export const QuizCreator: React.FC = ({ onFinalize, onCancel } const [questions, setQuestions] = useState([]); const [qText, setQText] = useState(''); const [options, setOptions] = useState(['', '', '', '']); + const [reasons, setReasons] = useState(['', '', '', '']); const [correctIdx, setCorrectIdx] = useState(0); const handleAddQuestion = () => { @@ -28,7 +29,8 @@ export const QuizCreator: React.FC = ({ onFinalize, onCancel } text, isCorrect: idx === correctIdx, shape: shapes[idx], - color: colors[idx] + color: colors[idx], + reason: reasons[idx].trim() || undefined })); const newQuestion: Question = { @@ -41,6 +43,7 @@ export const QuizCreator: React.FC = ({ onFinalize, onCancel } setQuestions([...questions, newQuestion]); setQText(''); setOptions(['', '', '', '']); + setReasons(['', '', '', '']); setCorrectIdx(0); }; @@ -123,26 +126,39 @@ export const QuizCreator: React.FC = ({ onFinalize, onCancel } const bgClass = COLORS[['red','blue','yellow','green'][idx] as any]; return ( -
- - -
+
+
+ + +
+ { + const newOpts = [...options]; + newOpts[idx] = e.target.value; + setOptions(newOpts); + }} + className="w-full p-2 outline-none font-bold text-gray-700 bg-transparent placeholder:font-normal" + placeholder={`Option ${idx + 1}`} + /> +
{ - const newOpts = [...options]; - newOpts[idx] = e.target.value; - setOptions(newOpts); + const newReasons = [...reasons]; + newReasons[idx] = e.target.value; + setReasons(newReasons); }} - className="w-full p-2 outline-none font-bold text-gray-700 bg-transparent placeholder:font-normal" - placeholder={`Option ${idx + 1}`} + className="w-full p-2 ml-12 text-sm outline-none text-gray-500 bg-gray-50 rounded-lg placeholder:text-gray-400" + placeholder={isSelected ? "Why is this correct? (optional)" : "Why is this wrong? (optional)"} />
) diff --git a/components/RevealScreen.tsx b/components/RevealScreen.tsx index b8bbdb5..02f7b2c 100644 --- a/components/RevealScreen.tsx +++ b/components/RevealScreen.tsx @@ -65,6 +65,16 @@ export const RevealScreen: React.FC = ({

{correctOption.text}

+ {correctOption.reason && ( + + {correctOption.reason} + + )}
); @@ -110,9 +120,16 @@ export const RevealScreen: React.FC = ({ className="flex flex-col items-center" > {isCorrect ? ( -
- +{pointsEarned} - Points +
+
+ +{pointsEarned} + Points +
+ {correctOption.reason && ( +

+ {correctOption.reason} +

+ )}
) : (
@@ -133,24 +150,34 @@ export const RevealScreen: React.FC = ({
- {!isCorrect && ( - -

The correct answer was

-
-
- -
- {correctOption.text} -
-
- )} + + {!isCorrect && ( +
+ +

The correct answer was

+
+
+
+ +
+ {correctOption.text} +
+ {correctOption.reason && ( +

+ {correctOption.reason} +

+ )} +
+
+
+ )}
); }; diff --git a/services/geminiService.ts b/services/geminiService.ts index 06e1519..4e4131a 100644 --- a/services/geminiService.ts +++ b/services/geminiService.ts @@ -13,7 +13,7 @@ const getClient = () => { export const generateQuiz = async (topic: string): Promise => { const ai = getClient(); - const prompt = `Generate a trivia quiz about "${topic}". Create 10 engaging multiple-choice questions. Each question must have exactly 4 options, and exactly one correct answer. Vary the difficulty.`; + const prompt = `Generate a trivia quiz about "${topic}". Create 10 engaging multiple-choice questions. Each question must have exactly 4 options, and exactly one correct answer. Vary the difficulty. For each option, provide a brief reason explaining why it is correct or incorrect - this helps players learn.`; const response = await ai.models.generateContent({ model: "gemini-3-flash-preview", @@ -36,9 +36,10 @@ export const generateQuiz = async (topic: string): Promise => { type: Type.OBJECT, properties: { text: { type: Type.STRING }, - isCorrect: { type: Type.BOOLEAN } + isCorrect: { type: Type.BOOLEAN }, + reason: { type: Type.STRING, description: "Brief explanation of why this answer is correct or incorrect" } }, - required: ["text", "isCorrect"] + required: ["text", "isCorrect", "reason"] }, } }, @@ -68,7 +69,8 @@ export const generateQuiz = async (topic: string): Promise => { text: opt.text, isCorrect: opt.isCorrect, shape: shapes[index % 4], - color: colors[index % 4] + color: colors[index % 4], + reason: opt.reason })); return { diff --git a/types.ts b/types.ts index 563429d..f9590f3 100644 --- a/types.ts +++ b/types.ts @@ -16,6 +16,7 @@ export interface AnswerOption { isCorrect: boolean; shape: 'triangle' | 'diamond' | 'circle' | 'square'; color: 'red' | 'blue' | 'yellow' | 'green'; + reason?: string; // Explanation for why this answer is correct or incorrect } export interface Question {