Skip to content

An AI skill that turns books into animated, narrated, interactive web experiences

21.1 KB
Raw Blame
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Measures of Central Tendency and Variation — Elementary Algebra</title>
<link rel="stylesheet" href="../lib/engine.css">
<link rel="expect" href="#bar" blocking="render"><!-- hold the first frame until the player exists, so the page transition can run -->
</head>
<body>
<script src="../lib/engine.js"></script>
<script src="../lib/math.js"></script>
<script src="audio/en/timings.js"></script>
<script>
'use strict';
const CHAPTER = { number: 40, title: 'Measures of Central Tendency and Variation', minutes: 8, next: '../ch41/' };
const MEAN = COL.whole, MED = COL.rat, MODE = COL.int, RNG = COL.real;

/* ---------- chapter drawing helpers ---------- */
const mline = (p, parts, x, y, t0, fill = COL.chalk, size = 48, anchor = 'middle') => { const e = M(p, [].concat(parts), { x, y, size, fill, anchor, o: 0 }); show(e, t0); return e; };
const text = (p, str, x, y, t0, { size = 30, fill = COL.chalk, anchor = 'start', weight = 500 } = {}) => { const e = T(p, str, { x, y, size, fill, anchor, weight, o: 0 }); show(e, t0); return e; };
// A rounded name tag, centred on (x, y).
function tag(p, str, color, x, y, t0, w = 220) {
  const g = G(p, { x, y, s: .6, o: 0 });
  mk('rect', { x: -w / 2, y: -36, width: w, height: 72, rx: 36, fill: mix(COL.board, color, .22), stroke: color, 'stroke-width': 3 }, g);
  T(g, str, { y: 12, size: 34, fill: color, weight: 600, anchor: 'middle' });
  pop(g, t0);
  return g;
}
// Bar chart on a baseline: one bar per value, u pixels per unit. Heights tween with a_y / a_height.
const BY = 720, BX = i => 250 + i * 160, BW = 104;
function barSet(p, vals, u, t0, color = MEAN) {
  const bars = vals.map((v, i) => {
    const b = put(rect(p, BX(i) - BW / 2, BY, BW, 0, mix(COL.board, color, .55), 1, color), { a_y: BY, a_height: 0 });
    tw(b, { a_y: BY - v * u, a_height: v * u }, t0 + i * .25, .7, out);
    return b;
  });
  const labels = vals.map((v, i) => text(p, String(v), BX(i), BY - v * u - 16, t0 + i * .25 + .5, { size: 34, anchor: 'middle', weight: 600 }));
  vals.forEach((v, i) => text(p, `game ${i + 1}`, BX(i), BY + 40, t0, { size: 22, fill: COL.dim, anchor: 'middle' }));
  path(p, `M${BX(0) - 90} ${BY}H${BX(vals.length - 1) + 90}`, { stroke: COL.dim, 'stroke-width': 3 });
  return { bars, labels };
}
// Move a block along an arc: up and over, then down into place.
function arcMove(e, dx, dy, t0, dur = 1.1, lift = 90, run = prog) {
  const { x, y } = st(e);
  run(q => put(e, { x: x + dx * q, y: y + dy * q - Math.sin(Math.PI * q) * lift }), t0, dur);
}
// Number chips in slots along a row; returns the chips (each remembers its value).
const SLOT = (i, n, gap = 200) => 800 + (i - (n - 1) / 2) * gap;
function chipRow(p, vals, y, t0, color = COL.chalk, gap = 200) {
  return vals.map((v, i) => {
    const c = chip(p, [String(v)], color, { x: SLOT(i, vals.length, gap), y, size: 46, s: 0, o: 0 });
    c.v = v;
    pop(c, t0 + i * .12);
    return c;
  });
}
// Cross off the chip at (x, y): a slash, and the chip fades.
function strike(p, c, x, y, t0, color = COL.dim) {
  draw(path(p, `M${x - 70} ${y + 26}L${x + 70} ${y - 26}`, { stroke: color, 'stroke-width': 4 }, { d: 0 }), t0, .35);
  tw(c, { o: .35 }, t0 + .2, .4);
}

/* ---------- beats ---------- */
const BEATS = [
  ['intro', 'Measures of center', (m, D) => {
    const g = G(scene, { o: 0, y: 24 });
    T(g, 'Unit 7, Chapter 40', { x: 800, y: 300, size: 28, fill: COL.dim, anchor: 'middle' });
    T(g, 'Measures of Central Tendency', { x: 800, y: 400, size: 76, weight: 600, anchor: 'middle' });
    T(g, 'and Variation', { x: 800, y: 490, size: 76, weight: 600, anchor: 'middle' });
    tw(g, { o: 1, y: 0 }, .2, 1.1, out);
    const r = text(scene, 'one number for the middle  ·  one for the spread', 800, 620, m('sub'), { size: 34, fill: COL.dim, anchor: 'middle' });
    tw(g, { o: 0, y: -24 }, D - .9, .8); hide(r, D - .9, .8);
  }],
  ['set', 'Data sets', (m) => {
    const p = panel(0);
    text(p, 'a data set', 800, 160, .2, { size: 28, fill: COL.dim, anchor: 'middle' });
    chipRow(p, [7, 3, 9, 5, 6, 9, 4], 250, .3, COL.chalk, 150);
    text(p, 'measures of central tendency: where is the middle?', 120, 450, m('c'), { size: 30, fill: COL.dim });
    tag(p, 'Mean', MEAN, 250, 550, m('mean'));
    tag(p, 'Median', MED, 510, 550, m('med'));
    tag(p, 'Mode', MODE, 770, 550, m('mode'));
    text(p, 'the average', 250, 630, m('mean', .3), { size: 24, fill: COL.dim, anchor: 'middle' });
    text(p, 'the middle value', 510, 630, m('med', .3), { size: 24, fill: COL.dim, anchor: 'middle' });
    text(p, 'the most common', 770, 630, m('mode', .3), { size: 24, fill: COL.dim, anchor: 'middle' });
    path(p, 'M1000 420V670', { stroke: COL.faint, 'stroke-width': 2 });
    text(p, 'measure of variation: how spread out?', 1060, 450, m('var'), { size: 30, fill: COL.dim });
    tag(p, 'Range', RNG, 1270, 550, m('range'));
    text(p, 'the spread', 1270, 630, m('range', .3), { size: 24, fill: COL.dim, anchor: 'middle' });
  }],
  ['mean', 'The mean', (m) => {
    const p = panel(0);
    S.bars = G(scene);
    const B = S.b = barSet(S.bars, [12, 19, 23, 10], 18, m('data'));
    text(p, 'points in four games', 160, 150, m('data'), { size: 30, fill: COL.dim });
    text(p, 'mean = sum ÷ number of values', 1240, 180, .3, { size: 32, fill: MEAN, anchor: 'middle', weight: 600 });
    B.labels.forEach((l, i) => pulse(l, m('add', .2 + i * .35), 1.3));
    mline(p, '12 + 19 + 23 + 10 = 64', 1240, 330, m('add', .2), COL.chalk, 52);
    text(p, 'add all the values', 1240, 380, m('add', .2), { size: 24, fill: COL.dim, anchor: 'middle' });
    bracketH(p, BX(0) - BW / 2, BX(3) + BW / 2, BY + 66, '4 values', MEAN, m('div', 1));
    mline(p, '64 ÷ 4 = 16', 1240, 480, m('div', 1.5), COL.chalk, 52);
    text(p, 'divide by how many', 1240, 530, m('div', 1.5), { size: 24, fill: COL.dim, anchor: 'middle' });
    const a = G(p, { x: 1240, y: 640, s: .6, o: 0 });
    mk('rect', { x: -170, y: -50, width: 340, height: 80, rx: 16, fill: 'none', stroke: MEAN, 'stroke-width': 3 }, a);
    M(a, ['mean = 16'], { y: 6, size: 50, fill: MEAN });
    pop(a, m('ans'));
  }],
  ['level', 'A fair share', (m) => {
    const p = panel(0), U = 18, Yv = v => BY - v * U, { bars, labels } = S.b;
    const line = path(p, `M${BX(0) - 90} ${Yv(16)}H${BX(3) + 90}`, { stroke: MEAN, 'stroke-width': 3, 'stroke-dasharray': '10 8' }, { o: 0, 'a_stroke-width': 3 });
    show(line, m('line'));
    text(p, 'mean 16', BX(3) + 104, Yv(16) + 9, m('line'), { size: 28, fill: MEAN, weight: 600 });
    // Extra points above the line: two pieces from the 23 bar, one from the 19 bar.
    const piece = (i, lo, hi) => rect(p, BX(i) - BW / 2, Yv(hi), BW, (hi - lo) * U, mix(COL.board, COL.task, .6), 0, COL.task);
    const pa = piece(2, 16, 20), pb = piece(2, 20, 23), pc = piece(1, 16, 19);
    [pa, pb, pc].forEach((e, i) => show(e, m('extra', i * .2)));
    const gaps = [[0, 12], [3, 10]].map(([i, v]) => {
      const g = put(mk('rect', { x: BX(i) - BW / 2, y: Yv(16), width: BW, height: (16 - v) * U, fill: 'none', stroke: COL.dim, 'stroke-width': 2.5, 'stroke-dasharray': '7 6' }, p), { o: 0 });
      show(g, m('short', i * .2));
      return g;
    });
    [1, 2].forEach(i => tw(bars[i], { a_y: Yv(16), a_height: 16 * U }, m('move'), .01));
    labels.forEach(l => hide(l, m('move'), .3));
    arcMove(pc, BX(3) - BX(1), Yv(13) - Yv(19), m('move'), 1);
    arcMove(pb, BX(3) - BX(2), Yv(16) - Yv(23), m('move', .6), 1);
    arcMove(pa, BX(0) - BX(2), Yv(16) - Yv(20), m('move', 1.1), 1.1, 120);
    gaps.forEach(g => hide(g, m('even')));
    [0, 1, 2, 3].forEach(i => text(p, '16', BX(i), Yv(16) - 16, m('even', i * .15), { size: 34, fill: MEAN, anchor: 'middle', weight: 600 }));
    tw(line, { 'a_stroke-width': 6 }, m('even', .6), .3); tw(line, { 'a_stroke-width': 3 }, m('even', 1), .4);
    text(p, '64 points shared evenly', 1240, 330, m('fair'), { size: 34, anchor: 'middle', weight: 600 });
    text(p, 'by 4 games is 16 each', 1240, 380, m('fair', .4), { size: 34, anchor: 'middle', weight: 600 });
  }],
  ['q1', 'Quick check', () => {
    const p = panel(0);
    hide(S.bars, 0, .4);
    text(p, 'minutes of practice on four days', 160, 150, .2, { size: 30, fill: COL.dim });
    S.qb = barSet(p, [7, 3, 9, 5], 30, .3);
  }, { ask: done => quiz({ x: 960, y: 180, w: 560, cls: 'side' }, [{
    id: 'c-mean', prompt: ['Find the mean of ', $m('7, 3, 9, 5'), '.'],
    build: blanks([{ parts: ['mean = ', { box: '6' }], why: '7 + 3 + 9 + 5 = 24, and 24 ÷ 4 = 6.', hint: 'Add the four values, then divide by 4.',
      fx: () => {
        const L = S.q || qlayer();
        S.qb.bars.forEach(b => fx(b, { a_y: BY - 180, a_height: 180 }, .2, .9));
        S.qb.labels.forEach(l => fx(l, { o: 0 }, 0, .3));
        const ln = path(L, `M${BX(0) - 90} ${BY - 180}H${BX(3) + 90}`, { stroke: MEAN, 'stroke-width': 3, 'stroke-dasharray': '10 8' }, { o: 0 });
        fx(ln, { o: 1 }, .9, .4);
        [0, 1, 2, 3].forEach(i => fx(T(L, '6', { x: BX(i), y: BY - 196, size: 34, fill: MEAN, anchor: 'middle', weight: 600, o: 0 }), { o: 1 }, 1 + i * .1, .3));
      } }]),
  }], done) }],
  ['median', 'The median', (m) => {
    const p = panel(0);
    text(p, 'jump rope jumps', 800, 200, m('jumps'), { size: 30, fill: COL.dim, anchor: 'middle' });
    const cs = S.mc = chipRow(p, [130, 85, 150, 210, 100], 360, m('jumps', .3));
    const order = [...cs].sort((a, b) => a.v - b.v);
    order.forEach((c, k) => {
      const from = cs.indexOf(c), dx = SLOT(k, 5) - SLOT(from, 5);
      if (dx) arcMove(c, dx, 0, m('sort', .3 + k * .15), 1.1, dx > 0 ? 80 : -80);
    });
    const ar = G(p, { o: 0 });
    path(ar, `M${SLOT(0, 5)} 470H${SLOT(4, 5)}M${SLOT(4, 5) - 16} 460L${SLOT(4, 5)} 470L${SLOT(4, 5) - 16} 480`, { stroke: COL.dim, 'stroke-width': 3 });
    T(ar, 'least', { x: SLOT(0, 5), y: 510, size: 24, fill: COL.dim, anchor: 'middle' });
    T(ar, 'greatest', { x: SLOT(4, 5), y: 510, size: 24, fill: COL.dim, anchor: 'middle' });
    show(ar, m('sort', 1.4));
    [[0, 4], [1, 3]].forEach(([a, b], j) => [a, b].forEach(k => strike(p, order[k], SLOT(k, 5), 360, m('cross', j * 1.1))));
    const mid = order[2];
    tw(mid, { s: 1.25 }, m('mid'), .4, back);
    tw(mid._rect, { c_stroke: MED }, m('mid'), .3);
    put(mid._rect, { c_stroke: COL.chalk });
    mline(p, 'median = 130', 800, 620, m('mid', .5), MED, 56);
  }],
  ['even', 'Two middle values', (m) => {
    const p = panel(0);
    const cs = chipRow(p, [14, 26, 40, 53], 220, m('set'));
    const D = dataLine(p, { lo: 10, hi: 60, x0: 300, x1: 1300, y: 720, step: 5, every: 2, t0: m('set', .4) });
    D.dots([14, 26, 40, 53], COL.chalk, m('set', .8), .15);
    [0, 3].forEach(k => strike(p, cs[k], SLOT(k, 4), 220, m('pair', k * .2)));
    [1, 2].forEach(k => { tw(cs[k]._rect, { c_stroke: MED }, m('pair', .6), .3); put(cs[k]._rect, { c_stroke: COL.chalk }); });
    mline(p, ['(26 + 40) ÷ 2 = 66 ÷ 2 = 33'], 800, 380, m('avg'), COL.chalk, 50);
    D.mark(33, MED, m('ans'), 'median 33');
    D.span(26, 33, 600, '7', MED, m('ans', .8));
    D.span(33, 40, 600, '7', MED, m('ans', 1.2));
    text(p, 'halfway between the two middle values', 800, 480, m('ans', 1.6), { size: 28, fill: MED, anchor: 'middle' });
  }],
  ['q2', 'Quick check', () => {
    const p = panel(0);
    text(p, 'points scored in five games', 800, 220, .2, { size: 30, fill: COL.dim, anchor: 'middle' });
    S.row = tokens(p, ['9', '      ', '4', '      ', '12', '      ', '7', '      ', '15'], { x: 800, y: 420, size: 84, anchor: 'middle', o: 0 });
    S.row.forEach((e, i) => show(e, .3 + i * .05));
  }, { ask: done => quiz(BAND, [{
    id: 'c-median', prompt: ['Click the median of these five values.'],
    build: tapEls(S.row, [0, 2, 4, 6, 8], 0, 'In order the values are 4, 7, 9, 12, 15, and 9 is in the middle.',
      i => i === 4 ? '12 is in the middle of the list, but the list is not in order yet. Sort first: 4, 7, 9, 12, 15.'
        : `Sort the values first: 4, 7, 9, 12, 15. Which one has two values on each side?`,
      () => {
        const nums = [0, 2, 4, 6, 8].map(i => S.row[i]), slots = nums.map(e => e._px);
        [4, 7, 9, 12, 15].forEach((v, k) => { const e = nums.find(n => n.textContent.trim() === String(v)); fx(e, { x: slots[k] }, .2 + k * .1, .8); });
        floatText('sorted: least to greatest', 800, 300, MED);
      }),
  }], done) }],
  ['mode', 'The mode', (m) => {
    const p = panel(0);
    text(p, 'quiz scores out of 10', 180, 200, m('plot'), { size: 30, fill: COL.dim });
    const D = dataLine(p, { lo: 4, hi: 10, x0: 220, x1: 880, y: 660, t0: m('plot'), r: 17 });
    D.dots([6, 8, 7, 8, 9, 8, 5, 7, 10], MODE, m('plot', 1), .35, { from: 260 });
    const box = put(mk('rect', { x: D.V(8) - 32, y: 528, width: 64, height: 124, rx: 20, fill: 'none', stroke: MODE, 'stroke-width': 3.5 }, p), { o: 0 });
    show(box, m('tall'));
    mline(p, 'mode = 8', D.V(8), 500, m('tall', .4), MODE, 46);
    path(p, 'M1000 260V720', { stroke: COL.faint, 'stroke-width': 2 });
    text(p, 'two values tie', 1060, 300, m('two'), { size: 28, fill: COL.dim });
    tokens(p, ['2,  ', { t: '3,  3,', fill: MODE }, '  ', { t: '5,  5', fill: MODE }], { x: 1060, y: 370, size: 48, o: 0 }).forEach(e => show(e, m('two', .4)));
    text(p, 'two modes: 3 and 5', 1060, 420, m('two', 1), { size: 28, fill: MODE, weight: 600 });
    text(p, 'nothing repeats', 1060, 540, m('none'), { size: 28, fill: COL.dim });
    mline(p, '1,  4,  6,  9', 1060, 610, m('none', .4), COL.chalk, 48, 'start');
    text(p, 'no mode', 1060, 660, m('none', 1), { size: 28, fill: MODE, weight: 600 });
  }],
  ['range', 'The range', (m) => {
    const p = panel(0);
    const A = dataLine(p, { lo: 0, hi: 16, x0: 140, x1: 940, y: 370, every: 2, t0: m('a'), r: 14 });
    const B = dataLine(p, { lo: 0, hi: 16, x0: 140, x1: 940, y: 720, every: 2, t0: m('a', .3), r: 14 });
    text(p, 'group A', 120, 170, m('a'), { size: 28, fill: COL.whole, weight: 600 });
    text(p, 'group B', 120, 520, m('a', .3), { size: 28, fill: COL.nat, weight: 600 });
    A.dots([6, 7, 8, 8, 9, 10], COL.whole, m('a', .4), .1);
    const bd = B.dots([2, 4, 8, 8, 12, 14], COL.nat, m('a', 1), .1);
    A.mark(8, MEAN, m('bal'), 'mean 8');
    B.mark(8, MEAN, m('bal', .3), 'mean 8');
    bd.forEach((d, i) => pulse(d, m('diff', i * .1), 1.4));
    path(p, 'M1020 160V780', { stroke: COL.faint, 'stroke-width': 2 });
    text(p, 'range = maximum − minimum', 1070, 230, m('def'), { size: 32, fill: RNG, weight: 600 });
    A.span(6, 10, 250, '4', RNG, m('ra'));
    mline(p, '10 − 6 = 4', 1070, 380, m('ra', .4), COL.chalk, 50, 'start');
    text(p, 'group A', 1070, 320, m('ra', .4), { size: 24, fill: COL.whole });
    B.span(2, 14, 600, '12', RNG, m('rb'));
    mline(p, '14 − 2 = 12', 1070, 540, m('rb', .4), COL.chalk, 50, 'start');
    text(p, 'group B', 1070, 480, m('rb', .4), { size: 24, fill: COL.nat });
    text(p, 'bigger range: more spread out', 1070, 660, m('big'), { size: 28, fill: RNG, weight: 600 });
  }],
  ['q3', 'Quick check', () => {
    const p = panel(0);
    text(p, 'books read by nine students this summer', 140, 200, .2, { size: 30, fill: COL.dim });
    const D = S.qd = dataLine(p, { lo: 2, hi: 12, x0: 160, x1: 900, y: 660, t0: .2, r: 16 });
    D.dots([3, 4, 4, 6, 7, 7, 7, 9, 11], COL.whole, .4, .08);
  }, { ask: done => quiz({ x: 1000, y: 170, w: 540, cls: 'side' }, [{
    id: 'c-moderange', prompt: ['Find the mode and the range.'],
    build: blanks([
      { parts: ['mode = ', { box: '7' }], why: '7 appears three times, more than any other value.', hint: 'Which stack of dots is tallest?',
        fx: () => { const L = S.q || qlayer(), V = S.qd.V; const b = put(mk('rect', { x: V(7) - 30, y: 540, width: 60, height: 114, rx: 18, fill: 'none', stroke: MODE, 'stroke-width': 3.5 }, L), { o: 0 }); fx(b, { o: 1 }, 0, .4); } },
      { parts: ['range = ', { box: '8' }], why: 'The maximum is 11 and the minimum is 3: 11 − 3 = 8.', hint: 'Maximum minus minimum.',
        fx: () => S.qd.span(3, 11, 470, '11 − 3 = 8', RNG, 0, { run: fx, into: S.q || qlayer() }) },
    ]),
  }], done) }],
  ['outlier', 'Outliers', (m) => {
    const p = panel(0);
    const D = dataLine(p, { lo: 0, hi: 15, x0: 160, x1: 1000, y: 560, t0: m('four'), r: 15, size: 20 });
    text(p, 'slices of pizza', 160, 160, m('four'), { size: 30, fill: COL.dim });
    const l1 = mline(p, '2,  3,  2,  4', 160, 230, m('four'), COL.chalk, 46, 'start');
    D.dots([2, 3, 2, 4], COL.whole, m('four', .5), .2);
    const mn = D.mark(2.75, MEAN, m('mn'), 'mean');
    const md = G(p, { x: D.V(2.5), y: 560, o: 0 });
    path(md, 'M0 -10V-140', { stroke: MED, 'stroke-width': 3, 'stroke-dasharray': '8 6' });
    T(md, 'median', { y: -154, size: 24, fill: MED, weight: 600, anchor: 'middle' });
    show(md, m('md'));
    const v1 = mline(p, 'mean = 2.75', 1120, 330, m('mn'), MEAN, 44, 'start');
    const v2 = mline(p, 'median = 2.5', 1120, 420, m('md'), MED, 44, 'start');
    const o = D.dot(14, COL.bad, m('out'), { from: 300 });
    mline(p, ',  14', 160 + l1._w, 230, m('out'), COL.bad, 46, 'start');
    text(p, 'outlier', D.V(14), 490, m('out', .6), { size: 26, fill: COL.bad, anchor: 'middle', weight: 600 });
    D.slide(mn, 5, m('pull'), tw, 1.6);
    hide(v1, m('pull'), .3);
    mline(p, 'mean = 5', 1120, 330, m('pull', .8), MEAN, 44, 'start');
    tw(md, { x: D.V(3) }, m('stay'), .8);
    hide(v2, m('stay'), .3);
    S.medVal = mline(p, 'median = 3', 1120, 420, m('stay', .5), MED, 44, 'start');
    text(p, 'An outlier pulls the mean.', 1120, 520, m('skew'), { size: 26, fill: COL.dim });
    text(p, 'The median barely moves.', 1120, 560, m('skew', .4), { size: 26, fill: COL.dim });
  }],
  ['q4', 'Quick check', () => {}, { ask: done => quiz(BAND, [{
    id: 'c-outlier', prompt: ['Which number better describes how many slices a typical friend ate?'],
    build: choice([['the mean, ', $m('5')], ['the median, ', $m('3')]], 1, 'Four of the five friends ate 4 slices or fewer. The median, 3, sits among them.',
      ['Four of the five friends ate fewer than 5 slices. The outlier, 14, pulled the mean up.', null], () => pulseFx(S.medVal, 1.2)),
  }], done) }],
  ['wrap', 'Summary', (m) => {
    const p = panel(0);
    [['Mean: add the values, divide by how many.', 'w1', MEAN], ['Median: the middle value in order (or the mean of the two middle values).', 'w2', MED],
     ['Mode: the value that occurs most often.', 'w3', MODE], ['Range: maximum − minimum.', 'w4', RNG]].forEach(([str, mark, c], i) => {
      const g = G(p, { x: -16, y: 230 + i * 130, o: 0 });
      mk('circle', { cx: 170, cy: -12, r: 26, fill: c }, g);
      T(g, String(i + 1), { x: 170, y: -1, size: 30, fill: COL.board, weight: 700, anchor: 'middle' });
      T(g, str, { x: 230, size: 34, weight: 600 });
      tw(g, { o: 1, x: 0 }, m(mark), .6);
    });
  }],
  ['final1', 'Chapter practice', () => { panel(0); }, { ask: done => quiz(SCREEN, [{
    id: 'p-five', prompt: ['Data: ', $m('12, 15, 9, 15, 19'), '. Find each measure.'], build: blanks(MEASURES5),
  }], done, 'Chapter practice   1 of 3') }],
  ['final2', 'Chapter practice', () => {}, { ask: done => quiz(SCREEN, [{
    id: 'p-modes', prompt: ['How many modes does each data set have?'],
    build: grid(MODEQ, [['0', 'No mode', null, '0'], ['1', 'One mode', MODE, '1'], ['2', 'Two modes', MODE, '2']], { multi: false, text: true }),
  }], done, 'Chapter practice   2 of 3') }],
  ['final3', 'Chapter practice', () => {}, { ask: done => quiz(SCREEN, [{
    id: 'p-six', prompt: ['Data: ', $m('8, 3, 12, 5, 9, 5'), '. Find each measure.'], build: blanks(MEASURES6),
  }], done, 'Chapter practice   3 of 3') }],
  ['finish', 'Finished', () => {}, { ask: finishCard }],
].map(([id, title, run, extra]) => ({ id, title, run, ...extra }));

/* ---------- chapter practice data ---------- */
const MEASURES5 = [
  { parts: ['mean = ', { box: '14' }], why: '12 + 15 + 9 + 15 + 19 = 70, and 70 ÷ 5 = 14.', hint: 'Add the five values, then divide by 5.' },
  { parts: ['median = ', { box: '15' }], why: 'In order: 9, 12, 15, 15, 19. The middle value is 15.', hint: 'Put the values in order first.' },
  { parts: ['mode = ', { box: '15' }], why: '15 appears twice; every other value appears once.', hint: 'Which value appears most often?' },
  { parts: ['range = ', { box: '10' }], why: '19 − 9 = 10.', hint: 'Maximum minus minimum.' },
];
const MEASURES6 = [
  { parts: ['mean = ', { box: '7' }], why: '8 + 3 + 12 + 5 + 9 + 5 = 42, and 42 ÷ 6 = 7.', hint: 'Add the six values, then divide by 6.' },
  { parts: ['median = ', { box: '6.5' }], why: 'In order: 3, 5, 5, 8, 9, 12. The middle two are 5 and 8, and (5 + 8) ÷ 2 = 6.5.', hint: 'Sort the values. With six values, take the mean of the two middle ones.' },
  { parts: ['mode = ', { box: '5' }], why: '5 appears twice; every other value appears once.', hint: 'Which value appears most often?' },
  { parts: ['range = ', { box: '9' }], why: '12 − 3 = 9.', hint: 'Maximum minus minimum.' },
];
const MODEQ = [
  { parts: [$m('4, 7, 7, 9')], ans: ['1'], why: '7 appears twice.' },
  { parts: [$m('2, 5, 8, 11')], ans: ['0'], why: 'No value repeats.' },
  { parts: [$m('1, 1, 6, 6, 9')], ans: ['2'], why: '1 and 6 each appear twice.' },
  { parts: [$m('10, 20, 30, 10, 40')], ans: ['1'], why: '10 appears twice.' },
  { parts: [$m('6, 2, 9, 4, 7')], ans: ['0'], why: 'No value repeats.' },
  { parts: [$m('3, 8, 8, 5, 3, 1')], ans: ['2'], why: '3 and 8 each appear twice.' },
];
boot();
</script>
</body>
</html>