import { createMemo, createSignal } from "solid-js"; type Scenario = { id: string; prompt: string; imageSrc: string; imageAlt: string; correctAmount: 0 | 1; }; const SCENARIOS: Scenario[] = [ { id: "empty-box", prompt: "The box has no marbles inside.", imageSrc: "/chapters/math/zero-and-one/empty-box-std.jpg", imageAlt: "An empty box with nothing inside", correctAmount: 0, }, { id: "one-apple", prompt: "There is exactly one apple on the plate.", imageSrc: "/chapters/math/zero-and-one/app-plate-std.jpg", imageAlt: "A plate with one apple", correctAmount: 1, }, { id: "light-off", prompt: "The lamp is off — no light showing.", imageSrc: "/chapters/math/zero-and-one/lamp-off-std.jpg", imageAlt: "A lamp switched off", correctAmount: 0, }, { id: "light-on", prompt: "The lamp is on — one steady light.", imageSrc: "/chapters/math/zero-and-one/lamp-on-std.jpg", imageAlt: "A lamp switched on", correctAmount: 1, }, ]; function ZeroOneBoard() { const [index, setIndex] = createSignal(0); const [picked, setPicked] = createSignal<0 | 1 | null>(null); const scenario = createMemo(() => SCENARIOS[index() % SCENARIOS.length]); const atEnd = createMemo(() => index() >= SCENARIOS.length - 1); const amountCorrect = createMemo(() => { const p = picked(); return p !== null && p === scenario().correctAmount; }); const answered = createMemo(() => picked() !== null); const allCorrect = createMemo(() => answered() && amountCorrect()); const feedback = createMemo(() => { if (!answered()) return "Choose how many, then Next when you are ready."; if (allCorrect()) { return atEnd() ? "Well done — you can tell 0 from 1. Continue to Counting and numbers." : "Correct. Try the next situation."; } if (!amountCorrect()) { return picked() === 0 ? "Not quite — this situation is one, not zero." : "Not quite — this situation is zero, not one."; } return "Try again."; }); const pickAmount = (n: 0 | 1) => { setPicked(n); }; const goNext = () => { if (!answered() || !allCorrect()) return; if (atEnd()) return; setIndex((i) => i + 1); setPicked(null); }; const resetAll = () => { setIndex(0); setPicked(null); }; return (

Practice: zero or one

Situation {index() + 1} of {SCENARIOS.length}. Pick the amount that fits the image.

{scenario().prompt}

{scenario().imageAlt}

Your pick: {picked() === null ? "?" : picked()}

); } export default ZeroOneBoard;