Skip to content

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

15.3 KB
Raw Blame
<!doctype html>
<html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>Gratuity and Commission — 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}.band .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:23,title:'Gratuity and Commission',minutes:7,language:'en'};
// Colours: chalk = bill / sales, amber = rate, pink (rat) = tip added on top, blue = total paid, green (irr) = commission.
const TIP=COL.rat,TOT=COL.whole,COM=COL.irr;
const gcText=(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 gcMath=(p,s,x,y,t=0,size=52,col=COL.chalk,anchor='middle')=>{const e=M(p,Array.isArray(s)?s:[s],{x,y,size,fill:col,anchor,o:0});show(e,t);return e;};
const gcTitle=(p,s,sub='',ts=.15)=>{gcText(p,s,100,110,.1,43);if(sub)gcText(p,sub,100,165,ts,27,COL.dim);};
// bill strip at u px per dollar with the tip (pink) on its right end; tipAt: when the tip grows from nothing (null = drawn already)
function gcBar(p,x,y,u,bill,tip,t=0,h=100,tipAt=null){const g=G(p,{x,y,o:0});const b=mk('rect',{width:bill*u,height:h,fill:COL.chalk,'fill-opacity':.14,stroke:COL.chalk,'stroke-width':3},g);const e=mk('rect',{x:bill*u,width:tip*u,height:h,fill:TIP,'fill-opacity':.7,stroke:TIP,'stroke-width':3},g);if(tipAt!==null){put(e,{a_width:0,o:0});tw(e,{a_width:tip*u,o:1},tipAt,.9,out);}show(g,t);return {g,b,ex:e,w:(bill+tip)*u};}
// sales strip cut into $100 blocks; each block holds a green slice for the rate (0..1) at its foot
function gcSales(p,x,y,u,sales,rate,t=0,h=100,sliceAt=null){const g=G(p,{x,y,o:0}),bw=100*u,n=Math.round(sales/100),sl=[];for(let i=0;i<n;i++)mk('rect',{x:i*bw,width:bw,height:h,fill:COL.chalk,'fill-opacity':.14,stroke:COL.dim,'stroke-width':1.5},g);for(let i=0;i<n;i++){const s=mk('rect',{x:i*bw+1.5,y:h-Math.max(8,rate*h),width:bw-3,height:Math.max(8,rate*h),fill:COM},g);if(sliceAt!==null){put(s,{o:0});show(s,sliceAt+i*(1.6/n),.3);}sl.push(s);}mk('rect',{width:n*bw,height:h,fill:'none',stroke:COL.chalk,'stroke-width':3},g);show(g,t);return {g,sl,w:n*bw};}
function gcChoices(p,items,u){return items.map(([bill,tip,total],i)=>{const x=130+i*480,g=G(p);gcBar(g,x,360,u,bill,tip,0,100);gcText(g,String.fromCharCode(65+i),x+bill*u/2,270,0,34,COL.dim,'middle');gcText(g,'bill $'+bill,x,330,0,28);gcText(g,'+ tip $'+tip,x,500,0,29,TIP);gcText(g,'= total $'+total,x,550,0,31,TOT);return {el:g,box:[x-20,235,460,360],label:'Picture '+String.fromCharCode(65+i)+', bill '+bill+', tip '+tip+', total '+total};});}
// a paper receipt for the bill, drawn around its top-left corner
function gcReceipt(p,x,y){const g=G(p,{x,y});let d='M0 0H220V300';for(let i=0;i<11;i++)d+=`l-10 ${i%2?14:-14}l-10 ${i%2?-14:14}`;d+='Z';path(g,d,{fill:COL.chalk,'fill-opacity':.1,stroke:COL.chalk,'stroke-width':3});T(g,'BILL',{x:110,y:48,size:26,anchor:'middle',fill:COL.dim,weight:600});[90,130,170].forEach((yy,i)=>{path(g,`M28 ${yy}H${120-i*14}`,{stroke:COL.dim,'stroke-width':3});path(g,`M160 ${yy}H192`,{stroke:COL.dim,'stroke-width':3});});path(g,'M28 205H192',{stroke:COL.chalk,'stroke-width':2,'stroke-dasharray':'6 6'});T(g,'$25.00',{x:110,y:250,size:36,anchor:'middle',font:MATH});return g;}
// a price tag for the sales
function gcTag(p,x,y){const g=G(p,{x,y});path(g,'M0 80L50 0H250V160H50Z',{fill:COL.chalk,'fill-opacity':.1,stroke:COL.chalk,'stroke-width':3});mk('circle',{cx:40,cy:80,r:11,fill:'none',stroke:COL.chalk,'stroke-width':3},g);path(g,'M29 80C-10 60 -20 20 10 -10',{stroke:COL.dim,'stroke-width':2.5});T(g,'SOLD',{x:150,y:62,size:26,anchor:'middle',fill:COL.dim,weight:600});T(g,'$3,500',{x:150,y:118,size:40,anchor:'middle',font:MATH});return g;}
const BEATS=[
['intro','Gratuity and Commission',(m,D)=>{const g=G(scene,{o:0,y:24});T(g,'Unit 2 · Ratios, Proportions, and Percents · Chapter 23',{x:800,y:195,size:28,fill:COL.dim,anchor:'middle'});T(g,'Gratuity and Commission',{x:800,y:390,size:90,weight:600,anchor:'middle'});T(g,'amount = rate × total',{x:800,y:560,size:50,fill:COL.task,anchor:'middle'});tw(g,{o:1,y:0},.2,1,out);gcText(g,'A tip for service · a share of what you sell',800,720,m('sub'),35,COL.dim,'middle');hide(g,D-.8,.7);}],
['words','Two new words',m=>{const p=panel(0);gcTitle(p,'Two new words','Both are a percent of a total');
const L=G(p,{o:0});gcReceipt(L,180,240);T(L,'Gratuity',{x:460,y:300,size:50,weight:600,fill:TIP});T(L,'a tip, given for service',{x:460,y:360,size:30});const lb=T(L,'a percent of the bill',{x:460,y:410,size:29,fill:COL.dim});show(L,m('grat'));
const R=G(p,{o:0});gcTag(R,870,300);T(R,'Commission',{x:1180,y:300,size:50,weight:600,fill:COM});T(R,'a fee for selling',{x:1180,y:360,size:30});const rb=T(R,'a percent of the sales',{x:1180,y:410,size:29,fill:COL.dim});show(R,m('com'));
tw(lb,{c_fill:COL.task},m('both'),.5);tw(rb,{c_fill:COL.task},m('both',1.6),.5);
gcText(p,'found just like sales tax (Chapter 21)',800,660,m('tax'),32,COL.dim,'middle');gcText(p,'amount = rate × total',800,760,m('rule'),58,COL.task,'middle');}],
['tip','A 15% tip',m=>{const p=panel(0);gcTitle(p,'A $25 dinner bill · 15% tip','The tip is 15% of the bill, added on top');const b=gcBar(p,160,250,32,25,3.75,m('bill'),100,m('tip'));gcText(p,'bill $25',560,312,m('bill'),34,COL.chalk,'middle');gcText(p,'tip $3.75',1020,230,m('tip',.3),32,TIP,'middle');
const br=path(p,'M160 372V390H1080V372',{stroke:TOT,'stroke-width':4},{d:0});draw(br,m('add'),.8);gcText(p,'total $28.75',620,436,m('add',.4),36,TOT,'middle');
gcMath(p,'15% = 0.15',800,540,m('conv'),50,COL.task);gcMath(p,'25 × 0.15 = 3.75',800,640,m('mult'),54,TIP);gcMath(p,'25 + 3.75 = 28.75',800,740,m('add'),54,TOT);gcText(p,'one step: 1.15 × 25 = 28.75',800,830,m('one'),34,COL.dim,'middle');}],
['prop','Bigger bill, bigger tip',m=>{const p=panel(0);gcTitle(p,'Same 15% tip · different bills','Each strip: 8 px = $1');
[[20,3,'b20'],[40,6,'b40'],[80,12,'b80']].forEach(([bill,tip,k],i)=>{const y=270+i*150,g=G(p,{x:120,y,o:0});gcBar(g,0,0,8,bill,tip,0,60);T(g,'bill $'+bill,{x:0,y:-16,size:28});T(g,'tip $'+tip,{x:bill*8+8,y:-16,size:28,fill:TIP});show(g,m(k));if(i)pulse(g,m('double',.2+i*.5),1.03);});
// tip-vs-bill graph: origin (1040,720), 4.6 px per bill dollar, 26 px per tip dollar
const ox=1040,oy=720,gx=v=>ox+v*4.6,gy=v=>oy-v*26,A=G(p,{o:0});path(A,`M${ox} ${gy(16)}V${oy}H${gx(104)}`,{stroke:COL.dim,'stroke-width':3});[20,40,60,80,100].forEach(v=>{path(A,`M${gx(v)} ${oy}v10`,{stroke:COL.dim,'stroke-width':2});T(A,String(v),{x:gx(v),y:oy+38,size:28,fill:COL.dim,anchor:'middle',font:MATH});});[3,6,9,12,15].forEach(v=>{path(A,`M${ox} ${gy(v)}h-10`,{stroke:COL.dim,'stroke-width':2});T(A,String(v),{x:ox-18,y:gy(v)+10,size:28,fill:COL.dim,anchor:'end',font:MATH});});T(A,'bill ($)',{x:gx(104),y:oy+80,size:30,fill:COL.dim,anchor:'end'});T(A,'tip ($)',{x:ox,y:gy(16)-18,size:30,fill:COL.dim,anchor:'middle'});show(A,m('same'));
const ln=path(p,`M${ox} ${oy}L${gx(100)} ${gy(15)}`,{stroke:COL.task,'stroke-width':4},{d:0});draw(ln,m('line'),1.2);
[[20,3,'b20'],[40,6,'b40'],[80,12,'b80']].forEach(([v,w,k])=>{const d=G(p,{x:gx(v),y:gy(w),s:0,o:0});mk('circle',{r:11,fill:TIP},d);pop(d,m(k,.3));});
gcText(p,'double the bill → double the tip',120,760,m('double'),34,COL.task);gcText(p,'tip = 0.15 × bill: the tip is proportional to the bill',800,850,m('prop'),32,COL.chalk,'middle');}],
['q1','Which picture?',()=>{const p=panel(0);gcTitle(p,'A $40 bill · 20% tip','Same scale in each picture: 7 px = $1');S.gcCh=gcChoices(p,[[40,'0.80','40.80'],[40,8,48],[40,20,60]],7);},{ask:done=>quiz(BAND,[{id:'c-tip',prompt:'Which picture shows a 20% tip on the $40 bill?',build:pickEls(S.gcCh,1,'0.20 × 40 = 8, so the tip is $8 and the total is 40 + 8 = $48.',i=>i===0?'$0.80 is 2% of $40. For 20%, multiply by 0.20, not 0.02.':'$20 is half the bill, which is 50%. 20% of $40 is $8.')}],done)}],
['commission','A 12% commission',m=>{const p=panel(0);gcTitle(p,'A summer job · 12% commission on sales','Her first week: $3,500 of clothes sold',m('sales'));const s=gcSales(p,160,250,.24,3500,.12,m('sales'),160,m('cut'));gcText(p,'12% commission on her sales',1040,252,m('deal'),34,COM);gcText(p,'35 blocks of $100',160,232,m('sales',2),27,COL.dim);
gcText(p,'12% of each block',1040,310,m('cut'),32,COM);gcText(p,'= $12 of every $100',1040,356,m('cut',.6),28,COL.dim);
const bar=mk('rect',{x:160,y:440,width:3500*.12*.24,height:100,fill:COM,'fill-opacity':.75,stroke:COM,'stroke-width':3},p);put(bar,{a_width:0,o:0});tw(bar,{a_width:3500*.12*.24,o:1},m('earn'),.9,out);gcText(p,'her commission: $420',290,503,m('earn',.3),34,COM);
gcMath(p,'12% = 0.12',800,625,m('conv'),50,COL.task);gcMath(p,'3,500 × 0.12 = 420',800,720,m('mult'),54,COM);
gcText(p,'The customer pays $3,500 either way; the store pays her $420 of it.',800,810,m('note'),31,COL.dim,'middle');}],
['proportion','Or use a proportion',m=>{const p=panel(0);gcTitle(p,'Same commission · as a proportion','A percent is a rate out of 100');
gcMath(p,[F('12','100'),' = ',F('x','3,500')],440,330,m('set'),64,COL.chalk);
gcText(p,'cross-multiply',140,450,m('cross'),30,COL.task);gcMath(p,'100x = 12 × 3,500',140,525,m('eq'),48,COL.chalk,'start');gcMath(p,'100x = 42,000',140,615,m('prod'),48,COL.chalk,'start');gcText(p,'÷ 100 on both sides',520,612,m('div'),28,COL.dim);gcMath(p,'x = 420',140,715,m('x'),56,COM,'start');
const tb=G(p,{o:0});T(tb,'sales ($)',{x:1110,y:290,size:28,fill:COL.dim,anchor:'middle'});T(tb,'commission ($)',{x:1340,y:290,size:28,fill:COL.dim,anchor:'middle'});path(tb,'M1000 312H1460M1225 255V520',{stroke:COL.dim,'stroke-width':2});M(tb,['100'],{x:1110,y:395,size:46,anchor:'middle'});M(tb,['12'],{x:1340,y:395,size:46,anchor:'middle'});M(tb,['3,500'],{x:1110,y:495,size:46,anchor:'middle'});const xq=M(tb,['x'],{x:1340,y:495,size:46,anchor:'middle'});show(tb,m('set'));
const x420=gcMath(p,'420',1340,495,m('x'),46,COM);hide(xq,m('x'),.3);
const ar=G(p,{o:0});path(ar,'M990 368Q950 425 990 482M977 468L991 484L998 463',{stroke:COL.task,'stroke-width':3});T(ar,'× 35',{x:950,y:436,size:30,fill:COL.task,anchor:'end'});path(ar,'M1470 368Q1510 425 1470 482M1483 468L1469 484L1462 463',{stroke:COL.task,'stroke-width':3});T(ar,'× 35',{x:1510,y:436,size:30,fill:COL.task});show(ar,m('scale'));pulse(x420,m('scale',4),1.25);
gcText(p,'12 out of 100 is the same rate as 420 out of 3,500',800,830,m('same'),32,COL.chalk,'middle');}],
['q2','Find the commission',()=>{const p=panel(0);gcTitle(p,'$2,400 of furniture sold · 6% commission','Each block = $100; green = 6% of the block');gcSales(p,160,260,.35,2400,.06,0,160);gcText(p,'sales $2,400',160,470,0,30);},{ask:done=>quiz(BAND,[{id:'c-com',prompt:'How much does the salesperson earn?',build:blanks([{parts:['6% of $2,400 = $',{box:'144'}],why:'0.06 × 2,400 = 144: $6 from each of the 24 hundreds.',hint:'Change 6% to 0.06 (not 0.6), then multiply by 2,400.'}])}],done)}],
['compare','Commission or a flat fee?',m=>{const p=panel(0);gcTitle(p,'Amber: 12% commission or a $500 flat fee?','Her sales for the period: $3,950',m('sales'));
gcMath(p,'0.12 × 3,950 = 474',800,270,m('calc'),50,COM);
const x0=440,u=1.3;
const l1=gcText(p,'12% of sales?',x0-24,386,m('offer'),30,COM,'end'),l2=gcText(p,'$500 flat',x0-24,496,m('offer',3.5),30,COL.chalk,'end');
[340,450].forEach((y,i)=>{const r=G(p,{o:0});mk('rect',{x:x0,y,width:500*u,height:70,fill:'none',stroke:COL.dim,'stroke-width':2,'stroke-dasharray':'8 8'},r);show(r,m('offer',i*3.5));});
const b1=G(p,{x:x0,y:340,o:0}),b2=G(p,{x:x0,y:450,o:0});mk('rect',{width:474*u,height:70,fill:COM,'fill-opacity':.7,stroke:COM,'stroke-width':3},b1);T(b1,'$474',{x:474*u-16,y:48,size:34,fill:COL.board,anchor:'end',weight:600});
const r2=mk('rect',{width:500*u,height:70,fill:COL.chalk,'fill-opacity':.18,stroke:COL.chalk,'stroke-width':3},b2);T(b2,'$500',{x:500*u+18,y:48,size:32});show(b2,m('offer',5));show(b1,m('calc',1));
const dl=path(p,`M${x0+500*u} 322V540`,{stroke:COL.task,'stroke-width':3,'stroke-dasharray':'8 8'},{o:0});show(dl,m('pick'));tw(r2,{c_stroke:COL.task},m('pick',.4),.5);
gcText(p,'474 < 500 → choose the flat fee',800,625,m('pick'),40,TOT,'middle');
gcMath(p,'500 ÷ 0.12 ≈ 4,166.67',800,725,m('even'),44,COL.task);gcText(p,'Commission pays more only when sales top about $4,166.67.',800,800,m('even',2),30,COL.dim,'middle');}],
['q3','Who received more?',()=>{const p=panel(0);gcTitle(p,'A tip and a commission');gcText(p,'Luke, a waiter',160,330,0,40,TIP);gcText(p,'bill $236 · 18% tip',160,390,0,36,COL.chalk);gcText(p,'Mary, an electronics seller',160,540,0,40,COM);gcText(p,'sales $380 · 12% commission',160,600,0,36,COL.chalk);},{ask:done=>quiz(BAND,[{id:'c-who',prompt:'Who received more money?',build:choice(['Luke','Mary','They received the same'],1,'Luke: 0.18 × 236 = $42.48. Mary: 0.12 × 380 = $45.60. Mary gets more, even with the smaller rate.',['A bigger rate is not enough: 0.18 × 236 = 42.48, but 0.12 × 380 = 45.60.','','Work out both: 0.18 × 236 = 42.48 and 0.12 × 380 = 45.60.'])}],done)}],
['wrap','Four habits',m=>{const p=panel(0);gcTitle(p,'Gratuity and commission · the same percent idea');[['Gratuity (tip): a percent of the bill. Commission: a percent of the sales.','w1'],['Change the percent to a decimal, then multiply by the total.','w2'],['A tip is added to the bill. A commission is a share of the sale.','w3'],['Or use a proportion: rate / 100 = amount / total.','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-tip',prompt:'Tips and totals. Type only the number of dollars, no $ or commas; round to the cent.',build:blanks([
{parts:['Lee family: $45 bill, 18% tip. Tip $',{box:'8.10'}],why:'0.18 × 45 = 8.10.'},
{parts:['Caterer: $875, 25% tip. Tip $',{box:'218.75'},'  total $',{box:'1093.75'}],why:'0.25 × 875 = 218.75, and 875 + 218.75 = 1,093.75.'},
{parts:['Babysitter: $70, 32% tip. Tip $',{box:'22.40'},'  total $',{box:'92.40'}],why:'0.32 × 70 = 22.40, and 70 + 22.40 = 92.40.'},
{parts:['Haircut: $25 with a 10% tip. Total $',{box:'27.50'}],why:'1.10 × 25 = 27.50.'},
{parts:['Dinner: $32.75 bill, 17% tip. Total $',{box:'38.32'}],why:'1.17 × 32.75 = 38.3175, which rounds to $38.32.'}
])}],done,'Chapter practice · set 1 of 2')}],
['final2','Chapter practice',()=>panel(0),{ask:done=>quiz(SCREEN,[{id:'p-com',prompt:'Commissions. Type only the number of dollars, no $ or commas.',build:blanks([
{parts:['35% of $6,000 in sales. Commission $',{box:'2100'}],why:'0.35 × 6,000 = 2,100.'},
{parts:['Julio sells scooters: 8% of $5,450. Commission $',{box:'436'}],why:'0.08 × 5,450 = 436.'},
{parts:['Mauricio: 8% of $25,000 = $',{box:'2000'},'   Judith: 9.5% of $22,000 = $',{box:'2090'}],why:'0.08 × 25,000 = 2,000 and 0.095 × 22,000 = 2,090: Judith earned more.'},
{parts:['Agent: 3% of a $250,000 house sale. Commission $',{box:'7500'}],why:'0.03 × 250,000 = 7,500.'}
])}],done,'Chapter practice · set 2 of 2')}],
['finish','Finished',()=>panel(0),{ask:finishCard}]
].map(([id,title,run,extra])=>({id,title,run,...extra}));
boot();
</script></body></html>