Skip to content

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

11.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>Simple Interest — 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: 16, title: 'Simple interest', minutes: 6, next: '../ch17/' };
const PR = COL.whole, IN = COL.irr, RT = COL.int, TM = COL.real, CP = COL.nat;

/* ---------- chapter drawing helpers ---------- */
const caption = (p, str, t0, y = 140, fill = COL.dim, size = 30, x = 800) => show(T(p, str, { x, y, size, fill, weight: 600, anchor: 'middle', o: 0 }), t0);
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; };
// Vertical bar chart of a balance: base = principal height, blocks stack on top. k = pixels per dollar.
function column(p, x, base, k, label, t0, { w = 110, y0 = 700, color = PR } = {}) {
  const g = G(p, { o: 0 });
  mk('rect', { x: x - w / 2, y: y0 - base * k, width: w, height: base * k, rx: 6, fill: color, 'fill-opacity': .5, stroke: color, 'stroke-width': 2.5 }, g);
  T(g, label, { x, y: y0 + 36, size: 24, fill: COL.dim, anchor: 'middle' });
  show(g, t0);
  let top = y0 - base * k;
  return {
    add(amount, color, t, text) {
      const h = amount * k, r = put(mk('rect', { x: x - w / 2, y: top - h, width: w, height: h, rx: 4, fill: color, 'fill-opacity': .75, stroke: color, 'stroke-width': 2 }, p), { o: 0, s: 1 });
      tw(r, { o: 1 }, t, .4);
      if (text) show(T(p, text, { x: x + w / 2 + 12, y: top - h / 2 + 9, size: 22, fill: color, font: MATH, o: 0 }), t + .2);
      top -= h;
      return r;
    },
  };
}

/* ---------- beats ---------- */
const BEATS = [
  ['intro', 'Simple interest', (m, D) => {
    const g = G(scene, { o: 0, y: 24 });
    T(g, 'Unit 3, Chapter 16', { x: 800, y: 330, size: 28, fill: COL.dim, anchor: 'middle' });
    T(g, 'Simple interest', { x: 800, y: 430, size: 96, weight: 600, anchor: 'middle' });
    tw(g, { o: 1, y: 0 }, .2, 1.1, out);
    const r = mline(scene, ['I = P · R · T'], 800, 590, m('q'), COL.dim, 56);
    tw(g, { o: 0, y: -24 }, D - .9, .8); hide(r, D - .9, .8);
  }],
  ['terms', 'Principal, rate, time', (m) => {
    const p = panel(0);
    [['P', 'principal', 'the amount saved or borrowed', PR, 'p'], ['R', 'rate', 'percent per year, as a decimal', RT, 'r'], ['T', 'time', 'in years', TM, 't']].forEach(([l, w, d, c, mark], i) => {
      const g = G(p, { x: -16, y: 220 + i * 120, o: 0 });
      T(g, l, { x: 260, size: 60, fill: c, font: MATH, weight: 600, anchor: 'middle' });
      T(g, w, { x: 330, y: -6, size: 36, fill: c, weight: 600 });
      T(g, d, { x: 560, y: -6, size: 28, fill: COL.dim });
      tw(g, { o: 1, x: 0 }, m(mark), .6);
    });
    const f = tokens(p, [{ t: 'I', fill: IN }, ' = ', { t: 'P', fill: PR }, ' · ', { t: 'R', fill: RT }, ' · ', { t: 'T', fill: TM }], { x: 800, y: 660, size: 80, anchor: 'middle', o: 0 });
    f.forEach((e, i) => show(e, m('f', i * .15)));
    show(T(p, 'interest = principal × rate × time', { x: 800, y: 740, size: 28, fill: COL.dim, anchor: 'middle', o: 0 }), m('f', 1.5));
  }],
  ['grow', 'Watching it grow', (m) => {
    const p = panel(0), k = 1.4;
    mline(p, ['$250 at 3% per year'], 800, 140, m('q'), COL.chalk, 48);
    const cols = [0, 1, 2, 3].map(y => column(p, 330 + y * 180, 250, k, y ? `year ${y}` : 'start', m('q', .5 + y * .2)));
    // year y adds a $7.50 block to every column from y onward, so later columns show the running total
    const add = (y, t) => { for (let j = y; j <= 3; j++) cols[j].add(7.5 * 6, IN, t + (j - y) * .15, j === y ? '+7.50' : ''); };
    add(1, m('y1')); add(2, m('y2')); add(3, m('y3'));
    caption(p, 'the same $7.50 every year', m('same'), 620, IN, 30, 1260);
    show(T(p, 'interest blocks drawn larger to be visible', { x: 1260, y: 670, size: 20, fill: COL.faint, anchor: 'middle', o: 0 }), m('y1'));
    mline(p, ['I = 250 × 0.03 × 3 = 22.50'], 1260, 400, m('calc'), COL.chalk, 38);
    mline(p, ['balance = 250 + 22.50'], 1260, 480, m('bal'), COL.chalk, 38);
    mline(p, ['= $272.50'], 1260, 550, m('bal', 1.5), COL.good, 44);
  }],
  ['q1', 'Quick check', () => { panel(0); }, { ask: done => quiz(BAND, [{
    id: 'c-interest', prompt: ['$500 is saved at 5% simple interest for 4 years. How much interest?'],
    build: blanks([{ parts: ['I = 500 × 0.05 × 4 = $', { box: '100' }], why: '500 × 0.05 = 25 a year, and 25 × 4 = 100.', hint: 'Write 5% as 0.05, then multiply all three.' }]),
  }], done) }],
  ['months', 'Time in years', (m) => {
    const p = panel(0);
    mline(p, ['8 months = ', F(8, 12), ' year = ', F(2, 3), ' year'], 800, 220, m('m'), TM, 50);
    mline(p, ['6 weeks = ', F(6, 52), ' year'], 800, 350, m('w'), TM, 50);
    mline(p, ['$900 at 6% for 8 months'], 800, 490, m('ex'), COL.chalk, 46);
    mline(p, ['I = 900 × 0.06 × ', F(2, 3), ' = $36'], 800, 610, m('calc'), COL.good, 50);
  }],
  ['time', 'Finding the time', (m) => {
    const p = panel(0);
    mline(p, ['$4000 at 4%.  How long to earn $600?'], 800, 140, m('q'), COL.chalk, 44);
    mline(p, ['600 = 4000 × 0.04 × T'], 800, 260, m('sub'), COL.chalk, 50);
    mline(p, ['600 = 160 T'], 800, 360, m('simp'), COL.chalk, 50);
    mline(p, ['T = 600 ÷ 160 = 3.75 years'], 800, 460, m('div'), COL.good, 50);
    const x0 = 300, u = 220;
    for (let y = 0; y < 4; y++) {
      const w = y < 3 ? u : .75 * u;
      const r = rect(p, x0 + y * (u + 10), 560, w, 60, IN);
      r.setAttribute('fill-opacity', .55); show(r, m('check', y * .4));
      show(T(p, y < 3 ? '$160' : '$120', { x: x0 + y * (u + 10) + w / 2, y: 600, size: 26, fill: COL.chalk, font: MATH, anchor: 'middle', o: 0 }), m('check', y * .4 + .2));
    }
    show(T(p, '3 years and 9 months:  160 + 160 + 160 + 120 = 600', { x: 800, y: 690, size: 28, fill: COL.dim, anchor: 'middle', o: 0 }), m('check', 2));
  }],
  ['q2', 'Quick check', () => { panel(0); }, { ask: done => quiz(BAND, [{
    id: 'c-time', prompt: ['$3000 is saved at 4% a year. How long until it earns $600?'],
    build: blanks([{ parts: ['600 = 3000 × 0.04 × T:   T = ', { box: '5' }, ' years'], why: '3000 × 0.04 = 120 a year, and 600 ÷ 120 = 5.', hint: 'How much interest is earned in one year?' }]),
  }], done) }],
  ['compound', 'Compound interest', (m) => {
    const p = panel(0), k = .9;
    mline(p, ['$1000 at 2%'], 800, 140, m('q'), COL.chalk, 48);
    show(T(p, 'simple', { x: 500, y: 220, size: 30, fill: IN, weight: 600, anchor: 'middle', o: 0 }), m('q'));
    show(T(p, 'compound', { x: 1100, y: 220, size: 30, fill: CP, weight: 600, anchor: 'middle', o: 0 }), m('q'));
    const s = column(p, 500, 300, k, 'after 2 years', m('q', .5), { w: 160 }), c = column(p, 1100, 300, k, 'after 2 years', m('q', .5), { w: 160 });
    s.add(20 * 3, IN, m('y1'), '+$20'); c.add(20 * 3, CP, m('y1'), '+$20');
    s.add(20 * 3, IN, m('y2s'), '+$20');
    c.add(20.4 * 3, CP, m('y2c'), '+$20.40');
    mline(p, ['$1040'], 500, 770, m('y2s', 1), IN, 40);
    mline(p, ['$1040.40'], 1100, 770, m('y2c', 2), CP, 40);
    // between the columns, clear of the optional captions at the bottom of the frame
    caption(p, 'compound interest earns', m('gap'), 580, COL.task);
    caption(p, 'interest on interest', m('gap'), 622, COL.task);
    show(T(p, 'interest blocks drawn larger to be visible', { x: 800, y: 460, size: 20, fill: COL.faint, anchor: 'middle', o: 0 }), m('y1'));
  }],
  ['q3', 'Quick check', () => { panel(0); }, { ask: done => quiz(BAND, [{
    id: 'c-loan', prompt: ['Tyler borrows $2000 at 9.5% simple interest for 2 years. How much does he pay back in all?'],
    build: blanks([{ parts: ['interest $', { box: '380' }, ',   total $', { box: '2380' }], why: '2000 × 0.095 × 2 = 380, and 2000 + 380 = 2380.', hint: 'Find the interest first, then add the principal.' }]),
  }], done) }],
  ['wrap', 'Summary', (m) => {
    const p = panel(0);
    [['Simple interest: I = P · R · T.', 'w1'], ['Rate as a decimal, time in years.', 'w1'],
     ['Balance = principal + interest.', 'w2'], ['Missing value: put in what you know, then divide.', 'w3']].forEach(([str, mark], i) => {
      const g = G(p, { x: -16, y: 230 + i * 120, o: 0 });
      mk('circle', { cx: 200, cy: -12, r: 26, fill: COL.task }, g);
      T(g, String(i + 1), { x: 200, y: -1, size: 30, fill: COL.board, weight: 700, anchor: 'middle' });
      T(g, str, { x: 260, size: 34, weight: 600 });
      tw(g, { o: 1, x: 0 }, m(mark, i === 1 ? 1 : 0), .6);
    });
  }],
  ['final1', 'Chapter practice', () => { panel(0); }, { ask: done => quiz(SCREEN, [{
    id: 'p-interest', prompt: ['$1500 is saved at 3.25% simple interest for 5 years.'], build: blanks(MARIO),
  }], done, 'Chapter practice   1 of 3') }],
  ['final2', 'Chapter practice', () => {}, { ask: done => quiz(SCREEN, [{
    id: 'p-back', prompt: ['Find each missing value.'], build: blanks(BACK),
  }], done, 'Chapter practice   2 of 3') }],
  ['final3', 'Chapter practice', () => {}, { ask: done => quiz(SCREEN, [{
    id: 'p-tf', prompt: ['True or false?'], build: grid(TFQ, TF, { multi: false, text: true }),
  }], done, 'Chapter practice   3 of 3') }],
  ['finish', 'Finished', () => {}, { ask: finishCard }],
].map(([id, title, run, extra]) => ({ id, title, run, ...extra }));

/* ---------- chapter practice data ---------- */
const MARIO = [
  { parts: ['rate as a decimal: R = ', { box: '0.0325' }], why: '3.25 ÷ 100 = 0.0325.' },
  { parts: ['interest after 5 years: $', { box: '243.75' }], why: '1500 × 0.0325 × 5 = 243.75.' },
  { parts: ['balance after 5 years: $', { box: '1743.75' }], why: '1500 + 243.75 = 1743.75.' },
  { parts: ['a $1200 loan at 5.4% for 1.5 years: repay $', { box: '1297.20' }], why: '1200 × 0.054 × 1.5 = 97.20, and 1200 + 97.20 = 1297.20.' },
];
const BACK = [
  { parts: ['$5000 at 8.5%: extra interest for 3 years instead of 2: $', { box: '425' }], why: 'One extra year: 5000 × 0.085 = 425.' },
  { parts: ['$800 earns $96 in 3 years. Rate: ', { box: '4' }, '%'], why: '96 = 800 × R × 3 = 2400R, so R = 0.04.' },
  { parts: ['At 5% for 2 years, interest is $150. Principal: $', { box: '1500' }], why: '150 = P × 0.05 × 2 = 0.1P, so P = 1500.' },
  { parts: ['$2400 at 2.5% earns $180 in ', { box: '3' }, ' years'], why: '2400 × 0.025 = 60 a year, and 180 ÷ 60 = 3.' },
];
const TFQ = [
  { parts: ['With simple interest, you earn the same interest every year.'], ans: ['t'], why: 'It is always a percent of the same principal.' },
  { parts: ['In I = P · R · T, a rate of 6% is entered as 6.'], ans: ['f'], why: 'Enter it as a decimal: 0.06.' },
  { parts: ['9 months is 0.75 of a year.'], ans: ['t'], why: '9/12 = 3/4 = 0.75.' },
  { parts: ['The balance is the interest minus the principal.'], ans: ['f'], why: 'The balance is principal plus interest.' },
  { parts: ['Compound interest earns interest on earlier interest.'], ans: ['t'], why: 'Each year uses the new balance.' },
];
boot();
</script>
</body>
</html>