An AI skill that turns books into animated, narrated, interactive web experiences
JavaScript ai-agentsai-educationanimationclaudeclaude-codeclaude-skillsedtecheducationinteractive-textbookscormtext-to-video
<!doctype html>
<html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>Discounts and Markups — Elementary Mathematics</title><link rel="stylesheet" href="../lib/engine.css"><link rel="expect" href="#bar" blocking="render"><style>.band .prompt{font-size:27px}.screen .blanks .bline{gap:12px}.screen .blanks .box{width:8ch!important}.screen .blanks .why{font-size:21px}.screen .blanks .bline svg tspan{font-style:normal}</style></head><body>
<script src="../lib/engine.js"></script><script src="audio/en/timings.js"></script><script>
'use strict';
const CHAPTER={number:22,title:'Discounts and Markups',minutes:9,language:'en', next: '../ch23/' };
// Colours: chalk = original price/cost, coral (nat) = discount, blue = pay / new price, pink (rat) = markup, amber = rate.
const DS=COL.nat,TOT=COL.whole,UP=COL.rat;
const dsText=(p,s,x,y,t=0,size=30,col=COL.chalk,anchor='start')=>{const e=T(p,s,{x,y,size,fill:col,anchor,o:0});show(e,t);return e;};
const dsMath=(p,s,x,y,t=0,size=52,col=COL.chalk)=>{const e=M(p,Array.isArray(s)?s:[s],{x,y,size,fill:col,anchor:'middle',o:0});show(e,t);return e;};
const dsTitle=(p,s,sub='')=>{dsText(p,s,100,110,.1,43);if(sub)dsText(p,sub,100,165,.15,27,COL.dim);};
// strip of the original price at u px per unit: blue = what you pay, coral = discount taken from the right end
function dsBar(p,x,y,u,price,off,t=0,h=100){const g=G(p,{x,y,o:0});const pay=mk('rect',{width:(price-off)*u,height:h,fill:TOT,'fill-opacity':.4,stroke:TOT,'stroke-width':3},g);const d=mk('rect',{x:(price-off)*u,width:off*u,height:h,fill:DS,'fill-opacity':.7,stroke:DS,'stroke-width':3},g);show(g,t);return {g,pay,d,w:price*u};}
// strip of the cost with a pink markup added to the right
function dsUp(p,x,y,u,cost,extra,t=0,h=100){const g=G(p,{x,y,o:0});mk('rect',{width:cost*u,height:h,fill:COL.chalk,'fill-opacity':.14,stroke:COL.chalk,'stroke-width':3},g);const e=mk('rect',{x:cost*u,width:extra*u,height:h,fill:UP,'fill-opacity':.7,stroke:UP,'stroke-width':3},g);show(g,t);return {g,ex:e,w:(cost+extra)*u};}
function dsBr(p,x,y,w,label,t){const g=G(p,{o:0});mk('path',{d:`M${x} ${y+14}V${y}H${x+w}V${y+14}`,fill:'none',stroke:COL.dim,'stroke-width':3},g);T(g,label,{x:x+w/2,y:y-12,size:32,fill:TOT,anchor:'middle'});show(g,t);}
function dsChoices(p,items,u){return items.map(([price,disc,pay],i)=>{const x=140+i*480,g=G(p),b=dsBar(g,x,360,u,price,disc,0,100);dsText(g,String.fromCharCode(65+i),x+(price*u)/2,270,0,34,COL.dim,'middle');dsText(g,'price $'+price,x,330,0,28);dsText(g,'discount $'+disc,x,500,0,29,DS);dsText(g,'pay $'+pay,x,550,0,31,TOT);return {el:g,box:[x-20,235,430,360],label:'Picture '+String.fromCharCode(65+i)+', price '+price+', discount '+disc+', pay '+pay,bar:b};});}
const BEATS=[
['intro','Discounts and Markups',(m,D)=>{const g=G(scene,{o:0,y:24});T(g,'Unit 2 · Ratios, Proportions, and Percents · Chapter 22',{x:800,y:195,size:28,fill:COL.dim,anchor:'middle'});T(g,'Discounts and Markups',{x:800,y:390,size:90,weight:600,anchor:'middle'});T(g,'price − discount · cost + markup',{x:800,y:560,size:50,fill:COL.task,anchor:'middle'});tw(g,{o:1,y:0},.2,1,out);dsText(g,'Take it off · put it on · work back',800,720,m('sub'),35,COL.dim,'middle');hide(g,D-.8,.7);}],
['discount','Discount: subtract it',m=>{const p=panel(0);dsTitle(p,'A $12.50 hat · all items 20% off','sale · markdown · clearance · savings: you subtract');const b=dsBar(p,200,250,96,12.5,2.5);put(b.d,{o:0});show(b.d,m('bar'));dsText(p,'original price $12.50',800,385,m('sign'),32,COL.chalk,'middle');const lb=G(p);dsText(lb,'discount',1280,225,m('bar'),30,DS,'middle');tw(lb,{y:70},m('sub'),.9,io);dsMath(p,'20% = 0.20',800,520,m('conv'),50,COL.task);dsMath(p,'0.20 × 12.50 = 2.50',800,625,m('mult'),54,DS);dsMath(p,'12.50 − 2.50 = 10.00',800,730,m('sub'),54,TOT);dsText(p,'new price $10.00',800,820,m('new'),38,TOT,'middle');tw(b.d,{y:70,o:.3},m('sub'),.9,io);}],
['pay','You pay what is left',m=>{const p=panel(0);dsTitle(p,'Same hat · what you pay','Pay = 100% − 20% = 80% of the price');const b=dsBar(p,200,250,96,12.5,2.5);put(b.d,{o:0});show(b.d,m('split'));dsText(p,'pay 80%',680,235,m('pct'),32,TOT,'middle');dsText(p,'save 20%',1280,235,m('split'),30,DS,'middle');dsMath(p,'100% − 20% = 80% = 0.80',800,520,m('pct'),50,COL.task);dsMath(p,'0.80 × 12.50 = 10.00',800,630,m('one'),56,TOT);dsText(p,'sale price = (1 − rate) × price',800,740,m('rule'),42,COL.task,'middle');}],
['q1','Which picture?',()=>{const p=panel(0);dsTitle(p,'A $60 jacket · 25% off','All strips use the same scale: 5 px = $1');S.dsCh=dsChoices(p,[[60,15,45],[60,25,35],[60,45,15]],5);},{ask:done=>quiz(BAND,[{id:'c-sale',prompt:'Which picture shows the jacket with 25% off?',build:pickEls(S.dsCh,0,'0.25 × 60 = 15 discount, so you pay 60 − 15 = $45.',i=>i===1?'$25 treats 25% as 25 dollars. 25% of $60 is only $15.':'$45 would be 75% off. 25% of $60 is $15.')}],done)}],
['twice','Two discounts, one at a time',m=>{const p=panel(0);dsTitle(p,'$100 of games · 25% off, then 15% more','The second discount is taken from the new price');const t1=dsBar(p,160,230,6,100,25,m('start'),70);put(t1.d,{o:0});show(t1.d,m('first'));dsText(p,'$100 · discount $25',160+225,335,m('first'),30,COL.chalk,'middle');const t2=dsBar(p,160,370,6,75,11.25,m('second'),70);dsText(p,'$75 · discount $11.25',160+170,475,m('second'),30,COL.chalk,'middle');dsMath(p,'0.25 × 100 = 25 → $75',1180,270,m('first',.3),44,DS,'middle');dsMath(p,'0.15 × 75 = 11.25 → $63.75',1180,410,m('second',.3),44,TOT);dsText(p,'not 40% off · that would be $60',800,610,m('wrong'),38,COL.task,'middle');dsText(p,'15% is of $75, not of $100',800,680,m('wrong',3),34,COL.dim,'middle');dsText(p,'total saved $36.25',800,760,m('wrong',6),38,DS,'middle');}],
['q2','Two discounts',()=>{const p=panel(0);dsTitle(p,'An $80 jacket · 10% off, then 10% more','One discount at a time');dsBar(p,160,260,8,80,8,0,70);dsText(p,'$80 · 10% off = $8',160+320,365,0,30,COL.chalk,'middle');},{ask:done=>quiz(BAND,[{id:'c-two',prompt:'Find the price after each discount.',build:blanks([{parts:['after the first: $',{box:'72'},' final price: $',{box:'64.80'}],why:'0.90 × 80 = 72, then 0.90 × 72 = 64.80. Not 20% off, which would be $64.'}])}],done)}],
['original','Work back to the original',m=>{const p=panel(0);dsTitle(p,'Sale price $41.99 · 30% off','What was the original price?');const b=dsBar(p,200,255,12,100,30);put(b.d,{o:0});show(b.d,m('pct'));dsText(p,'original price p = 100%',800,390,m('start'),32,COL.chalk,'middle');dsText(p,'30% off',1220,230,m('pct'),30,DS,'middle');dsText(p,'sale $41.99 = 70%',620,230,m('pct',1),30,TOT,'middle');dsMath(p,'100% − 30% = 70% = 0.7',800,520,m('pct',1),46,COL.task);dsMath(p,'41.99 = 0.7 × p',800,625,m('eq'),56);dsMath(p,'p = 41.99 ÷ 0.7 ≈ 59.99',800,730,m('divide'),56);dsText(p,'check: 0.7 × 59.99 = 41.993 ≈ 41.99',800,825,m('check'),33,COL.dim,'middle');}],
['mistake','Percent of the original',m=>{const p=panel(0);dsTitle(p,'A tempting shortcut','Add 30% of the sale price back?');dsMath(p,'41.99 + 0.3 × 41.99 ≈ 54.59',800,330,m('wrong'),54);const x=path(p,'M270 360L1330 300',{stroke:COL.bad,'stroke-width':6},{d:0});draw(x,m('why'),.6);dsText(p,'The 30% came off the original price, not off the sale price.',800,470,m('why'),34,COL.task,'middle');dsText(p,'test: 30% off $54.59 gives $38.21, not $41.99',800,570,m('test'),34,COL.dim,'middle');dsMath(p,'p = 41.99 ÷ 0.7 ≈ 59.99',800,735,m('right'),58,TOT);}],
['percentoff','Find the percent off',m=>{const p=panel(0);dsTitle(p,'Julie paid $35 for a $50 shirt','What was the percent discount?');const b=dsBar(p,200,250,24,50,15);put(b.d,{o:0});show(b.d,m('done'));dsText(p,'paid $35',620,235,m('paid'),32,TOT,'middle');dsText(p,'saved $15',1220,235,m('done'),30,DS,'middle');dsText(p,'original price $50',800,385,m('start'),32,COL.chalk,'middle');dsMath(p,'35 = x × 50 → x = 0.7',800,520,m('eq'),54);dsText(p,'Julie paid 70% of the price',800,605,m('paid'),36,TOT,'middle');dsMath(p,'1 − 0.7 = 0.3 = 30%',800,725,m('sub'),58,DS);dsText(p,'check: 15 ÷ 50 = 0.30',800,820,m('done',1),33,COL.dim,'middle');}],
['markup','Markup: add it',m=>{const p=panel(0);dsTitle(p,'A game costs the store $40 · 20% markup','markup = the increase that makes a profit');const b=dsUp(p,200,250,25,40,8);put(b.ex,{o:0});show(b.ex,m('bar'));dsText(p,'store pays $40',700,315,m('bar'),34,COL.chalk,'middle');dsText(p,'markup',1300,315,m('bar'),30,COL.chalk,'middle');dsBr(p,200,236,1200,'price $48',m('add'));dsMath(p,'20% = 0.20',800,520,m('conv'),50,COL.task);dsMath(p,'0.20 × 40 = 8',800,625,m('mult'),54,UP);dsMath(p,'40 + 8 = 48',800,730,m('add'),56,TOT);dsText(p,'one step: (1 + rate) × cost = 1.2 × 40',800,820,m('one'),34,COL.dim,'middle');}],
['markorig','Work back to the cost',m=>{const p=panel(0);dsTitle(p,'Cake price $5.08 · 70% markup','What did the bakery pay?');const b=dsUp(p,205,255,7,100,70);put(b.ex,{o:0});show(b.ex,m('pct'));dsText(p,'cost = 100%',555,320,m('start'),34,COL.chalk,'middle');dsText(p,'markup 70%',1150,320,m('pct'),30,COL.chalk,'middle');dsBr(p,205,241,1190,'price $5.08 = 170%',m('pct',3));dsMath(p,'100% + 70% = 170% = 1.7',800,520,m('pct',1),46,COL.task);dsMath(p,'5.08 = 1.7 × c',800,625,m('eq'),56);dsMath(p,'c = 5.08 ÷ 1.7 ≈ 2.99',800,730,m('divide'),56);dsText(p,'check: 1.7 × 2.99 = 5.083 ≈ 5.08',800,825,m('check'),33,COL.dim,'middle');}],
['updown','Down, then up',m=>{const p=panel(0);dsTitle(p,'A $200 bed · 30% off, then 20% markup','Each percent is of the price at that moment');const u1=dsBar(p,160,230,3,200,60,m('start'),70);put(u1.d,{o:0});show(u1.d,m('down'));dsText(p,'$200 − $60 = $140',160+210,335,m('down'),30,COL.chalk,'middle');const u2=dsUp(p,160,380,3,140,28,m('up'),70);dsText(p,'$140 + $28 = $168',160+210,485,m('up'),30,COL.chalk,'middle');dsMath(p,'0.30 × 200 = 60',1180,270,m('down'),44,DS,'middle');dsMath(p,'0.20 × 140 = 28',1180,425,m('up'),44,UP,'middle');dsText(p,'not 10% off ($180)',800,620,m('note'),40,COL.task,'middle');dsText(p,'The markup started from a smaller price.',800,700,m('note',5),34,COL.dim,'middle');dsText(p,'final price $168',800,790,m('note',8),42,TOT,'middle');}],
['q3','Up, then down',()=>{const p=panel(0);dsTitle(p,'$100 · marked up 25%, then marked down 25%','Does it come back to $100?');dsUp(p,160,230,6,100,25,0,70);dsText(p,'$100 + 25% = $125',160+375,335,0,30,COL.chalk,'middle');dsBar(p,160,370,6,125,31.25,0,70);dsText(p,'$125 − 25% of $125 = ?',160+375,475,0,30,COL.chalk,'middle');},{ask:done=>quiz(BAND,[{id:'c-updown',prompt:'Where does the price end?',build:choice(['$100','$93.75','$75'],1,'100 × 1.25 = 125, then 125 × 0.75 = 93.75. The 25% off is taken from the larger price.',['The two 25% steps are of different prices: $100 and then $125.','','That subtracts 25% from $100 but forgets the markup first.'])}],done)}],
['wrap','Four habits',m=>{const p=panel(0);dsTitle(p,'Discounts and markups · the same percent idea');[['Discount: a percent of the original price, subtracted. Markup: a percent of the cost, added.','w1'],['Sale price = (1 − rate) × price. Marked-up price = (1 + rate) × cost.','w2'],['To work back, divide by the same factor, such as 0.7 or 1.7.','w3'],['Two changes? Do one at a time, each from the current price.','w4']].forEach(([s,key],i)=>{const g=G(p,{x:-16,y:285+i*145,o:0});mk('circle',{cx:130,cy:-10,r:26,fill:COL.task},g);T(g,String(i+1),{x:130,y:0,size:30,anchor:'middle',fill:COL.board});T(g,s,{x:195,size:31});tw(g,{x:0,o:1},m(key),.6);});}],
['final1','Chapter practice',()=>panel(0),{ask:done=>quiz(SCREEN,[{id:'p-disc',prompt:'Discounts. Type only the number of dollars.',build:blanks([
{parts:['$300 computer, 15% off: discount $',{box:'45'},' price $',{box:'255'}],why:'0.15 × 300 = 45, and 300 − 45 = 255.'},
{parts:['$48 pants, 20% off: discount $',{box:'9.60'},' price $',{box:'38.40'}],why:'0.20 × 48 = 9.60, and 48 − 9.60 = 38.40.'},
{parts:['Truck A: $14,500, 10% off. Price $',{box:'13050'}],why:'0.90 × 14,500 = 13,050.'},
{parts:['Truck B: $16,000, 14% off. Price $',{box:'13760'}],why:'0.86 × 16,000 = 13,760.'}
])}],done,'Chapter practice · set 1 of 3')}],
['final2','Chapter practice',()=>panel(0),{ask:done=>quiz(SCREEN,[{id:'p-orig',prompt:'Work backward, or take two discounts. Type only the number.',build:blanks([
{parts:['Bike on sale for 45% off at $299.75. Original price $',{box:'545'}],why:'100% − 45% = 55%, and 299.75 ÷ 0.55 = 545.'},
{parts:['$30 shirt, 15% off, then 10% more. Final price $',{box:'22.95'}],why:'0.85 × 30 = 25.50, then 0.90 × 25.50 = 22.95.'},
{parts:['Paid $51 for a $60 shirt. Percent discount ',{box:'15'},' %'],why:'51 ÷ 60 = 0.85 is paid, so 1 − 0.85 = 0.15, which is 15%.'},
{parts:['Sale price $60, original price $80. Percent discount ',{box:'25'},' %'],why:'60 ÷ 80 = 0.75 is paid, so the discount is 0.25, which is 25%.'}
])}],done,'Chapter practice · set 2 of 3')}],
['final3','Chapter practice',()=>panel(0),{ask:done=>quiz(SCREEN,[{id:'p-mark',prompt:'Markups. Type only the number of dollars.',build:blanks([
{parts:['$50 shelf, 8% markup: markup $',{box:'4'},' new price $',{box:'54'}],why:'0.08 × 50 = 4, and 50 + 4 = 54.'},
{parts:['$350 bike, 15% markup: markup $',{box:'52.50'},' new price $',{box:'402.50'}],why:'0.15 × 350 = 52.50, and 350 + 52.50 = 402.50.'},
{parts:['Milk sells for $3.24 after a 35% markup. Cost $',{box:'2.40'}],why:'3.24 ÷ 1.35 = 2.40.'},
{parts:['Bed costs $200, marked down 30% then up 20%. Price $',{box:'168'}],why:'0.70 × 200 = 140, then 1.20 × 140 = 168.'}
])}],done,'Chapter practice · set 3 of 3')}],
['finish','Finished',()=>panel(0),{ask:finishCard}]
].map(([id,title,run,extra])=>({id,title,run,...extra}));
boot();
</script></body></html>