lmscn

Scramble

Letter-tile unscrambling activity with image and text clue support.

Installation

npx shadcn@latest add https://lmscn.vercel.app/r/scramble.json

Required primitives: button, progress, badge

npx shadcn@latest add button progress badge

Usage

import { Scramble } from "@/components/lms/scramble"
import type { ScrambleData, ScrambleResult } from "@/components/lms/scramble"

export function MyScramble() {
  return (
    <Scramble
      scrambleData={{
        title: "Science Terms",
        questions: [
          {
            id: "1",
            answer: "photosynthesis",
            clue: "How plants make food",
          },
          {
            id: "2",
            answer: "mitochondria",
            clue: "Powerhouse of the cell",
            clueImage: "/cell-diagram.png",
          },
        ],
      }}
      onComplete={(result: ScrambleResult) => {
        console.log(`${result.score} / ${result.maxScore}`)
      }}
    />
  )
}

Props

ScrambleProps

PropTypeRequiredDescription
scrambleDataScrambleDataQuestions configuration
onComplete(result: ScrambleResult) => voidCalled after the last question
classNamestringAdditional CSS classes

Data shape

ScrambleData

FieldTypeDescription
titlestringActivity title
descriptionstringSubtitle
questionsScrambleQuestion[]List of scramble questions

ScrambleQuestion

FieldTypeDescription
idstringUnique identifier
answerstringThe correct word or phrase. Spaces are stripped when building the tile pool
cluestringContext text shown above the tiles
clueImagestringURL of an optional image clue shown above the text clue

Result

onComplete receives a ScrambleResult object:

FieldTypeDescription
attemptsScrambleAttempt[]Per-question attempt records
scorenumberNumber of correct answers
maxScorenumberTotal number of questions
percentagenumberRounded score percentage
interface ScrambleAttempt {
  questionId: string
  given: string    // the word the learner assembled
  correct: boolean
}

Behaviour

  • The answer string is split into individual characters, shuffled, and displayed as a pool of clickable tiles at the bottom of the card.
  • Tapping a pool tile moves it into the answer tray at the top. Tapping a tray tile returns it to the pool.
  • The shuffler guarantees the initial order is never identical to the correct answer (for words longer than one character).
  • Reset returns all tray tiles back to the pool without re-shuffling.
  • Matching is case-insensitive.

On this page