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>Percent Word Problems — 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:20,title:'Percent Word Problems',minutes:13,language:'en', next: '../ch21/' };
// ch19 fixed-whole bars; blue = part, chalk = whole, amber = decimal rate/focus.
const wwText=(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 wwMath=(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 wwTitle=(p,s,sub='')=>{wwText(p,s,100,110,.1,43);if(sub)wwText(p,sub,100,165,.15,27,COL.dim);};
function wwBar(p,x,y,w,part,whole,t=0,h=110,cuts=10){const g=G(p,{x,y,o:0});g.dataset.whole=String(whole);g.dataset.part=String(part);const shade=mk('rect',{width:w*part/whole,height:h,fill:COL.whole,'fill-opacity':.55},g);const outline=mk('rect',{width:w,height:h,fill:'none',stroke:COL.chalk,'stroke-width':3},g);const lines=G(g);for(let i=1;i<cuts;i++)path(lines,`M${w*i/cuts} 0V${h}`,{stroke:COL.dim,'stroke-width':2});show(g,t);return {g,shade,outline,lines,w,h,part,whole};}
function wwRoleBar(p,part,whole,unit='meters',y=285){const b=wwBar(p,220,y,1160,part,whole);wwText(p,'WHOLE: '+whole+' '+unit+' = 100%',800,y-35,0,34,COL.chalk,'middle');wwText(p,'PART: '+part+' '+unit,220+1160*part/whole/2,y+165,0,34,COL.whole,'middle');return b;}
// labels(n,i): the text under each strip (q1: the blue amount; q2: the percent), so a choice never repeats the prompt.
function wwChoices(p,parts,whole,labels){return parts.map((n,i)=>{const x=140+i*480,g=G(p),b=wwBar(g,x,340,360,n,whole,0,110),[s,col,aria]=labels(n,i);wwText(g,String.fromCharCode(65+i),x+180,265,0,34,COL.dim,'middle');wwText(g,'whole '+whole+' meters',x+180,315,0,29,COL.chalk,'middle');wwText(g,s,x+180,520,0,36,col,'middle');return {el:g,box:[x-20,225,400,360],label:'Picture '+String.fromCharCode(65+i)+', '+aria,bar:b};});}
function wwCounters(p){const groups=[];for(let i=0;i<10;i++){const x=210+(i%5)*265,y=i<5?330:530,g=G(p,{o:i<4?1:0});g.dataset.groupId='group-'+i;const counters=[];for(let j=0;j<3;j++){const k=i*3+j,c=G(g,{x:i<4?250+k*100:x+j*60,y});c.dataset.counterId='unit-'+k;c.dataset.amount='1';mk('circle',{r:22,fill:i<4?COL.whole:COL.faint,stroke:i<4?COL.whole:COL.chalk,'stroke-width':2},c);counters.push(c);}const outline=G(g,{o:0});mk('rect',{x:x-32,y:y-50,width:184,height:100,rx:10,fill:'none',stroke:COL.task,'stroke-width':3},outline);groups.push({g,counters,outline,x,y});}return groups;}
const BEATS=[
['intro','Percent Word Problems',(m,D)=>{const g=G(scene,{o:0,y:24});T(g,'Unit 2 · Ratios, Proportions, and Percents · Chapter 20',{x:800,y:195,size:28,fill:COL.dim,anchor:'middle'});T(g,'Percent Word',{x:800,y:330,size:85,weight:600,anchor:'middle'});T(g,'Problems',{x:800,y:450,size:85,weight:600,anchor:'middle'});T(g,'part = decimal rate × whole',{x:800,y:590,size:48,fill:COL.task,anchor:'middle'});tw(g,{o:1,y:0},.2,1,out);wwText(g,'Find the missing role · check its meaning',800,745,m('sub'),35,COL.dim,'middle');hide(g,D-.8,.7);}],
['roles','Three roles',m=>{const p=panel(0);wwTitle(p,'One route · three roles','One full strip represents 80 meters');S.wwRoles=wwBar(p,220,295,1160,24,80);wwText(p,'WHOLE: 80 meters = 100%',800,255,m('whole'),36,COL.chalk,'middle');wwText(p,'PART: 24 meters',394,470,m('part'),33,COL.whole,'middle');wwText(p,'RATE: 30% = 0.30',394,530,m('rate'),36,COL.task,'middle');wwMath(p,'24 = 0.30 × 80',800,665,m('equation'),65);wwText(p,'part = decimal rate × whole',800,810,m('equation',2),36,COL.dim,'middle');}],
['translate','Words into a comparison',m=>{const p=panel(0);wwTitle(p,'What is 30% of 80?','Useful cues in this percent sentence · roles still come first');const X=[480,660,820,980,1140];[['What',COL.whole],['is',COL.chalk],['30%',COL.task],['of',COL.chalk],['80?',COL.chalk]].forEach(([word,col],i)=>wwText(p,word,X[i],310,0,64,col,'middle'));[['x','unknown part','unknown',COL.whole],['=','equals','is',COL.chalk],['30%','','of',COL.task],['×','times','of',COL.chalk],['80','','of',COL.chalk]].forEach(([sym,cap,key,col],i)=>{wwText(p,sym,X[i],425,m(key),58,col,'middle');if(cap)wwText(p,cap,X[i],475,m(key),26,COL.dim,'middle');});wwMath(p,'30% = 0.30',800,600,m('decimal'),49,COL.task);wwMath(p,'x = 0.30 × 80',800,720,m('decimal',3.8),64);wwText(p,'Identify the whole, part and rate; do not rely only on keywords.',800,835,m('roles',2),29,COL.dim,'middle');}],
['part','Find the part',m=>{const p=panel(0);wwTitle(p,'Find 30% of an 80-meter route','The whole stays 80 meters throughout.');S.wwPart=wwBar(p,220,280,1160,0,80);hide(S.wwPart.lines,0,0);show(S.wwPart.lines,m('tens'));wwText(p,'10 equal groups · each 10% = 8 meters',800,470,m('tens'),37,COL.task,'middle');for(let i=0;i<3;i++){const r=mk('rect',{x:i*116,y:0,width:116,height:110,fill:COL.whole,'fill-opacity':.55},S.wwPart.g);r.dataset.selectedGroup=String(i);put(r,{o:0});show(r,m('select')+i*.8,.5);}wwMath(p,'3 × 8 = 24',800,635,m('answer'),64,COL.whole);wwText(p,'30% of 80 meters = 24 meters',800,795,m('answer',2),40,COL.whole,'middle');}],
['multiply','Multiply rate by whole',m=>{const p=panel(0);wwTitle(p,'Find the part · multiply');S.wwMultiply=wwRoleBar(p,24,80);wwMath(p,'30% = 0.30',800,555,m('convert'),51,COL.task);wwMath(p,'x = 0.30 × 80 = 24',800,680,m('product'),61,COL.whole);wwText(p,'30% < 50% and 24 < 40',800,820,m('check'),34,COL.dim,'middle');}],
['q1','Choose the part',()=>{const p=panel(0);wwTitle(p,'Each whole is 40 meters','Pick the blue part that matches 30% of this whole.');S.wwChoices=wwChoices(p,[12,30,28],40,n=>['blue '+n+' meters',COL.whole,'blue '+n+' of 40 meters']);},{ask:done=>quiz(BAND,[{id:'c-part',prompt:'Which picture shows 30% of 40 meters?',build:pickEls(S.wwChoices,0,'0.30 × 40 = 12 meters. Picture A shades three of ten equal groups.',i=>i===1?'30 is the percent number, not the number of meters. Thirty meters would be 75% of forty.':'Twenty-eight meters is 70% of forty. We need the smaller thirty-percent part, twelve meters.')}],done)}],
['rate','Find the percent',m=>{const p=panel(0);wwTitle(p,'18 is what percent of 60?','r means the decimal rate · the whole is 60 meters');S.wwRate=wwRoleBar(p,18,60);wwMath(p,['r = ',F('18','60')],425,590,m('ratio'),58,COL.task);wwMath(p,'r = 0.30',1100,590,m('decimal'),57,COL.task);wwMath(p,'0.30 × 100 = 30 → 30%',800,755,m('percent'),63);wwText(p,'Decimal rate r = 0.30 · reported percent = 30%',800,835,m('percent',2),30,COL.dim,'middle');}],
['ratecheck','Check the decimal rate',m=>{const p=panel(0);wwTitle(p,'18 = r × 60','Part ÷ whole gives the decimal rate.');S.wwRateCheck=wwRoleBar(p,18,60);wwMath(p,'r = 18 ÷ 60 = 0.30',800,560,m('divide'),57,COL.task);wwMath(p,'0.30 × 60 = 18',800,695,m('check'),63,COL.whole);wwText(p,'meters ÷ meters: a ratio · report 30%, not 30 meters',800,825,m('units'),31,COL.dim,'middle');}],
['reverse','Same roles, different word order',m=>{const p=panel(0);wwTitle(p,'What percentage of 8 is 3?','Whole: 8 units · part: 3 units · missing: percent');S.wwReverse=wwBar(p,220,275,1160,3,8,0,110,8);wwText(p,'WHOLE: 8 units = 100%',800,240,m('roles'),34,COL.chalk,'middle');wwText(p,'PART: 3 units',437.5,440,m('roles'),32,COL.whole,'middle');wwMath(p,['r × 8 = 3 r = ',F('3','8'),' = 0.375'],800,595,m('ratio'),55,COL.task);wwMath(p,'0.375 × 100 = 37.5 → 37.5%',800,755,m('percent'),61);wwText(p,'Reported percent: 37.5% · exact, no rounding',800,835,m('percent',2),31,COL.dim,'middle');}],
['q2','Choose the percent',()=>{const p=panel(0);wwTitle(p,'18 meters of a 60-meter route are blue','What percent of the whole is that?');S.wwChoices=wwChoices(p,[18,1.8,42],60,(n,i)=>{const r=[30,3,70][i]+'%';return ['blue: '+r,COL.task,'blue '+r+' of 60 meters'];});},{ask:done=>quiz(BAND,[{id:'c-rate',prompt:'18 out of 60 meters is blue. Which percent is that?',build:pickEls(S.wwChoices,0,'18 ÷ 60 = 0.30, so 18 is 30% of 60. Picture A shades 30% of the whole.',i=>i===1?'3% of 60 is only 1.8. The decimal rate is 0.30, which converts to 30%.':'70% of 60 is 42. That is the unfilled share of the correct picture, not its eighteen-meter part.')}],done)}],
['whole','Reconstruct the whole',m=>{const p=panel(0);wwTitle(p,'12 is 40% of what whole?','Each counter = 1 unit · blue counters are the known part');S.wwGroups=wwCounters(p);S.wwTotal=wwText(p,'Visible total: 12 units',800,815,0,37,COL.chalk,'middle');S.wwGroups.slice(0,4).forEach(group=>{group.counters.forEach((c,j)=>tw(c,{x:group.x+j*60,y:group.y},m('groups'),2,io));show(group.outline,m('groups')+2);});wwText(p,'4 equal groups = 40%, so 1 group = 10% = 3 units',800,655,m('unit'),35,COL.task,'middle');S.wwGroups.slice(4).forEach(group=>put(group.outline,{o:1}));prog(q=>{const n=Math.floor(q*6+1e-8);S.wwGroups.slice(4).forEach((group,i)=>put(group.g,{o:i<n?1:0}));S.wwTotal.textContent='Visible total: '+(12+n*3)+' units';},m('extend'),4.8,lin);wwText(p,'10 equal groups = 100% · WHOLE = 30 units',800,735,m('answer'),35,COL.task,'middle');}],
['divide','Divide part by decimal rate',m=>{const p=panel(0);wwTitle(p,'Find the whole · 12 is 40% of w','The known part is 12 units, not the whole.');S.wwWhole=wwRoleBar(p,12,30,'units');wwMath(p,'w = 12 ÷ 0.40 = 30',800,550,m('divide'),62,COL.task);wwMath(p,'check: 0.40 × 30 = 12',800,670,m('check'),54,COL.whole);wwText(p,'12 × 0.40 = 4.8 answers a different question:',800,785,m('mistake'),30,COL.dim,'middle');wwText(p,'“What is 40% of 12?” treats 12 as the whole.',800,835,m('mistake',2),30,COL.dim,'middle');}],
['q3','Choose the whole',()=>{const p=panel(0);wwTitle(p,'Which whole has a 12-unit blue part at 40%?','All three strips are drawn to the same scale.');S.wwChoices=[30,4.8,20].map((whole,i)=>{const c=330+i*470,w=whole*15,x=c-w/2,g=G(p),b=wwBar(g,x,335,w,.4*whole,whole,0,110,whole<10?1:10);wwText(g,String.fromCharCode(65+i),c,250,0,34,COL.dim,'middle');wwText(g,'whole '+whole+' units',c,305,0,32,COL.chalk,'middle');wwText(g,'blue = 40% of this whole',c,520,0,30,COL.task,'middle');return {el:g,box:[c-235,220,470,340],label:'Whole '+whole+' units',bar:b};});},{ask:done=>quiz(BAND,[{id:'c-whole',prompt:'Choose the whole for which 12 is 40%.',build:pickEls(S.wwChoices,0,'12 ÷ 0.40 = 30 units. Forty percent of the 30-unit whole is exactly 12 units.',i=>i===1?'4.8 is 40% of 12. Its own forty-percent part is only 1.92, so it cannot have a twelve-unit part.':'Forty percent of 20 is 8, not 12. Divide the known part 12 by the decimal rate 0.40.')}],done)}],
['context','A savings goal',m=>{const p=panel(0);wwTitle(p,'$72 saved · keyboard price $240','What percent of the full price has Maya saved?');S.wwSavings=wwBar(p,220,295,1160,72,240);wwText(p,'WHOLE: $240 = 100%',800,255,m('whole'),35,COL.chalk,'middle');wwText(p,'PART: $72',394,465,m('whole'),34,COL.whole,'middle');wwMath(p,['r = ',F('72','240'),' = 0.30'],800,585,m('ratio'),57,COL.task);wwMath(p,'saved: 30%',800,720,m('percent'),63,COL.whole);wwText(p,'check: 0.30 × $240 = $72',800,835,m('check'),34,COL.dim,'middle');}],
['choose','Choose from the missing role',m=>{const p=panel(0);wwTitle(p,'Which role is missing?','One relationship · the missing role picks the operation');[['Missing part','part = decimal rate × whole','part',24,80],['Missing percent','decimal rate = part ÷ whole, then × 100','rate',18,60],['Missing whole','whole = part ÷ decimal rate','whole',12,30]].forEach(([role,eq,mark,part,whole],i)=>{const y=315+i*205,t=m(mark),bx=1030,bw=380,q=(s,k)=>k===mark?'?':s,qc=(k,col)=>k===mark?COL.task:col;wwText(p,role,120,y,t,35,COL.task);wwText(p,eq,120,y+62,t+.3,37,COL.chalk);wwBar(p,bx,y-30,bw,part,whole,t,74);wwText(p,'whole: '+q(String(whole),'whole'),bx+bw/2,y-48,t,28,qc('whole',COL.chalk),'middle');wwText(p,q(Math.round(100*part/whole)+'%','rate'),bx+bw*part/whole/2,y+17,t,30,qc('rate',COL.chalk),'middle');wwText(p,'part: '+q(String(part),'part'),bx+bw*part/whole/2,y+80,t,28,qc('part',COL.whole),'middle');});}],
['wrap','Four habits',m=>{const p=panel(0);wwTitle(p,'Meaning first · arithmetic second');[['Identify the whole: what represents 100%?','w1'],['Name the missing role: part, decimal rate or whole.','w2'],['Use part = decimal rate × whole; choose multiply or divide.','w3'],['Check in the original question; include units or %.','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-part',prompt:'Find the missing part. All answers exact; type only the number.',build:blanks([
{parts:['35% of 80 = ',{box:'28'}],why:'0.35 × 80 = 28. The rate is 0.35 and the whole is 80.'},
{parts:['12% of 250 = ',{box:'30'}],why:'0.12 × 250 = 30. Divide the percent number by 100 first.'},
{parts:['2.5% of 64 = ',{box:'1.6'}],why:'2.5% = 0.025; 0.025 × 64 = 1.6 exactly.'},
{parts:['125% of 32 = ',{box:'40'}],why:'1.25 × 32 = 40. The part exceeds the 32-unit reference whole because 125% exceeds 100%.'}
])}],done,'Chapter practice · set 1 of 3')}],
['final2','Chapter practice',()=>panel(0),{ask:done=>quiz(SCREEN,[{id:'p-rate',prompt:'Find the missing percent. Type the number before the printed % sign.',build:blanks([
{parts:['9 is ',{box:'25'},'% of 36'],why:'9 ÷ 36 = 0.25; convert that decimal rate to 25%.'},
{parts:['21 is ',{box:'35'},'% of 60'],why:'21 ÷ 60 = 0.35, so the reported percent is 35%.'},
{parts:['What percentage of 16 is 6? ',{box:'37.5'},'%'],why:'The part is 6, the whole is 16. 6 ÷ 16 = 0.375 = 37.5%.'},
{parts:['45 is ',{box:'150'},'% of 30'],why:'45 ÷ 30 = 1.5 = 150%. The reference whole stays 30; the compared amount is one and a half of those wholes.'}
])}],done,'Chapter practice · set 2 of 3')}],
['final3','Chapter practice',()=>panel(0),{ask:done=>quiz(SCREEN,[{id:'p-whole',prompt:'Find each missing whole. For the savings goal, enter dollars as a number.',build:blanks([
{parts:['18 is 30% of ',{box:'60'}],why:'18 ÷ 0.30 = 60; checking gives 0.30 × 60 = 18.'},
{parts:['14 is 35% of ',{box:'40'}],why:'14 ÷ 0.35 = 40; checking gives 0.35 × 40 = 14.'},
{parts:['6 is 2.5% of ',{box:'240'}],why:'2.5% = 0.025; 6 ÷ 0.025 = 240. The small rate requires a larger whole.'},
{parts:['$84 saved = 70% of a $',{box:'120'},' goal'],why:'84 ÷ 0.70 = 120 dollars. 70% of the $120 goal is $84.'}
])}],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>