Quiz with retries
Wrong answers play a short "try again" clip whose next points back to the question scene. Every visit to a scene re-arms its questions, so the question is asked again until it's answered right.
- Events will show up here.
Story
ts
import type { Story } from "@ivkit/core";
import { video } from "./video";
export const quiz: Story = {
version: "0.1",
start: "question",
scenes: {
question: {
src: video("quiz-question"),
events: [
{
type: "question",
id: "multiply",
at: 3,
text: "What is 7 × 6?",
options: [
{ id: "36", label: "36", goto: "wrong" },
{ id: "42", label: "42", goto: "right" },
{ id: "48", label: "48", goto: "wrong" },
],
},
],
},
// Loops back to the question, which is asked again on every visit.
wrong: { src: video("quiz-wrong"), next: "question" },
right: { src: video("quiz-right") },
},
};Scoring answers
Listen to iv-answer to keep score. The event's detail includes the question and the option that was picked:
ts
let attempts = 0;
player.addEventListener("iv-answer", (event) => {
const { question, choice } = event.detail;
if (question.id !== "multiply") return;
attempts++;
if (choice.id === "42") {
console.log(`Solved in ${attempts} ${attempts === 1 ? "try" : "tries"}`);
}
});Learn more: Branching and loops · Correct answers and replays · Player events