Skip to content

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

17.9 KB
Raw Blame
<!doctype html>
<html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1"><title>Adding and Subtracting Decimals — Elementary Mathematics</title><link rel="stylesheet" href="../lib/engine.css"><link rel="expect" href="#bar" blocking="render"><style>.screen .blanks .math{font-size:38px}.side .keys{font-size:20px}</style></head><body>
<script src="../lib/engine.js"></script><script src="audio/en/timings.js"></script><script>
'use strict';
const CHAPTER={number:8,title:'Adding and Subtracting Decimals',minutes:11,language:'en', next: '../ch09/' };
const dcText=(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 dcMath=(p,s,x,y,t=0,size=48,col=COL.chalk,anchor='middle')=>{const e=M(p,[s],{x,y,size,fill:col,anchor,o:0});show(e,t);return e;};
const dcTitle=(p,s,sub='')=>{dcText(p,s,100,120,.1,43);if(sub)dcText(p,sub,100,170,.15,27,COL.dim);};
function dcPiece(p,x,y,w,h,t=.2,col=COL.chalk){const e=G(p,{x,y,o:0});mk('rect',{width:w,height:h,fill:col,'fill-opacity':.30,stroke:col,'stroke-width':1.7},e);e.dataset.area=w*h;show(e,t);return e;}
function dcSquare(p,x,y,t=.2){return dcPiece(p,x,y,180,180,t);}
function dcStrips(p,n,x,y,t=.2,gap=18){return Array.from({length:n},(_,i)=>dcPiece(p,x+i*gap,y,18,180,t+i*.025));}
function dcCells(p,n,x,y,t=.2,cols=10,gap=18){return Array.from({length:n},(_,i)=>dcPiece(p,x+(i%cols)*gap,y+Math.floor(i/cols)*gap,18,18,t+i*.025));}
function dcBoard(p,{x=145,y=245,step=125,places=['ones','tenths','hundredths'],a=['2','6','8'],b=['1','5','7'],op='+',answer=[],t=.2,size=58}={}){
 const g=G(p,{x,y,o:0}),xs=places.map((_,i)=>i*step);show(g,t);
 places.forEach((s,i)=>T(g,s,{x:xs[i],y:0,size:places.length>4?20:23,fill:COL.dim,anchor:'middle'}));
 xs.forEach(xx=>path(g,`M${xx-step/2+7} 25V325`,{stroke:COL.faint,'stroke-width':1}));
 const dotx=(places.indexOf('ones')+.5)*step;
 const top=a.map((v,i)=>T(g,v,{x:xs[i],y:130,size,anchor:'middle'}));
 const bot=b.map((v,i)=>T(g,v,{x:xs[i],y:218,size,anchor:'middle'}));
 T(g,op,{x:-step*.8,y:218,size,anchor:'middle'});
 if(places.includes('tenths'))[130,218,325].forEach(yy=>T(g,'.',{x:dotx,y:yy,size,anchor:'middle'}));
 path(g,`M${-step*.9} 255H${xs.at(-1)+step*.5}`,{stroke:COL.chalk,'stroke-width':3});
 const ans=places.map((_,i)=>T(g,answer[i]??'',{x:xs[i],y:325,size,anchor:'middle',fill:COL.task,o:0}));
 return {g,top,bot,ans,xs:xs.map(xx=>xx+x),y,dotx:x+dotx};
}
function dcAnswer(board,arr,t){arr.forEach((v,i)=>{board.ans[i].textContent=v;show(board.ans[i],Array.isArray(t)?t[i]:t);});}
function dcCount(p,board,counts,t,label='regrouped counts'){
 const g=G(p,{o:0});counts.forEach((n,i)=>T(g,String(n),{x:board.xs[i],y:board.y+65,size:35,fill:COL.task,anchor:'middle'}));show(g,t);return g;
}
function dcCarry(p,board,i,t){dcText(p,'1',board.xs[i],board.y+65,t,34,COL.task,'middle');}
function dcPickBoard(p,x,y,correct,letter=correct?'A':'B'){const g=G(p);dcText(g,letter,x+170,y-90,.2,31,COL.dim,'middle');
 const rows=correct?['   8.400','+  0.675']:['     8.4','+  0.675'];rows.forEach((s,i)=>T(g,s,{x,y:y+i*85,size:64,font:'monospace'}));path(g,`M${x} ${y+112}H${x+325}`,{stroke:COL.chalk,'stroke-width':3});return {el:g,box:[x-20,y-55,390,210],label:letter+(correct?': decimal points aligned':': last digits aligned')};}
function dcZeroPick(p,x,value,place){const g=G(p);dcMath(g,value,x+165,285,.2,49);dcText(g,'7 wholes +',x+165,345,.2,27,COL.dim,'middle');if(place===1){dcStrips(g,3,x+120,385,.2,26);}else if(place===2){dcCells(g,3,x+120,460,.2,3,26);}else{for(let i=0;i<3;i++)dcPiece(g,x+120+i*26,460,1.8,18,.2);}dcText(g,place===1?'3 tenths':place===2?'3 hundredths':'3 thousandths',x+165,610,.2,27,COL.dim,'middle');return {el:g,box:[x+35,240,270,405],label:value};}
const BEATS=[
['intro','Same place, same pieces',(m,D)=>{const g=G(scene,{o:0,y:24});T(g,'Unit 1 · The Number System · Chapter 8',{x:800,y:265,size:28,fill:COL.dim,anchor:'middle'});T(g,'Adding and Subtracting',{x:800,y:375,size:78,weight:600,anchor:'middle'});T(g,'Decimals',{x:800,y:475,size:82,weight:600,anchor:'middle'});tw(g,{o:1,y:0},.2,1,out);dcMath(g,'2.68 + 1.57',800,590,.6,58);const s=dcText(scene,'Same place. Same-sized pieces.',800,710,m('sub'),34,COL.dim,'middle');hide(g,D-.8,.7);hide(s,D-.8,.7);}],
['places','Digits count sizes',m=>{const p=panel(0);dcTitle(p,'Place value gives each digit a home','Each whole square = 1 unit');dcSquare(p,220,320);dcText(p,'one whole',310,550,.2,30,COL.dim,'middle');const strips=dcStrips(p,10,220,320,m('tenths'));strips.forEach((e,i)=>tw(e,{x:540+i*18},m('tenths',.9),1.4,io));dcText(p,'10 tenths',630,550,m('tenths',2.5),30,COL.dim,'middle');dcCells(p,10,925,320,m('hundredths'),1);dcText(p,'1 tenth = 10 hundredths',1200,465,m('hundredths'),30,COL.task,'middle');
 [['2.68',400],['=',515],['2',610],['+',700],['0.6',810],['+',920],['0.08',1040]].forEach(([v,x])=>dcMath(p,v,x,705,m('columns'),55));
 [['wholes',610],['tenths',810],['hundredths',1040]].forEach(([v,x])=>dcText(p,v,x,775,m('columns',1),28,COL.dim,'middle'));}],
['align','Align sizes, not last digits',m=>{const p=panel(0);dcTitle(p,'8.4 + 0.675','Unequal decimal lengths need the same column homes.');const wrong=dcPickBoard(p,250,335,false,'A'),right=dcPickBoard(p,980,335,true,'B');put(wrong.el,{o:0});put(right.el,{o:0});show(wrong.el,.2);draw(path(p,'M220 270L635 455M220 455L635 270',{stroke:COL.task,'stroke-width':4},{d:0}),m('wrong'),.6);show(right.el,m('right'));dcText(p,'different places meet',430,560,m('wrong'),30,COL.task,'middle');dcText(p,'same places meet',1160,560,m('right'),30,COL.task,'middle');dcText(p,'Align decimal points → align place values.',800,745,m('rule'),40,COL.task,'middle');}],
['q1','Quick check',()=>{const p=panel(0);dcTitle(p,'Which board combines the same-sized places?');S.dcAlign=[dcPickBoard(p,285,360,true),dcPickBoard(p,1000,360,false)];},{ask:done=>quiz(BAND,[{id:'c-align',prompt:'Choose the correct setup for 8.4 + 0.675.',build:pickEls(S.dcAlign,0,'A aligns the decimal points: tenths meet tenths. Trailing zeros fill hundredths and thousandths.',()=> 'B lines up final digits, placing four tenths under five thousandths. Line up the decimal points.',()=>pulseFx(S.dcAlign[0].el,1.03))}],done)}],
['zeros','Trailing zeros keep the value',m=>{const p=panel(0);dcTitle(p,'7.3 = 7.30 = 7.300','Only trailing zeros: after the last decimal digit.');for(let j=0;j<3;j++)dcPiece(p,330+j*27,300,27,270,.2);dcText(p,'7 wholes + 3 tenths',370,625,.2,32,COL.dim,'middle');for(let j=0;j<3;j++)for(let i=1;i<10;i++)draw(path(p,`M${330+j*27} ${300+i*27}h27`,{stroke:COL.chalk,'stroke-width':1},{d:0}),m('split'),.5);dcText(p,'7 wholes + 30 hundredths',1030,370,m('split'),38,COL.task,'middle');dcMath(p,'7.300',1030,490,m('more'),72);dcText(p,'zero extra thousandths',1030,550,m('more'),30,COL.dim,'middle');dcMath(p,'5 = 5.00',1030,670,m('whole'),58);dcText(p,'7.03 ≠ 7.3 · moving the 3 changes its place',800,800,m('care'),34,COL.task,'middle');}],
['addhund','Trade ten hundredths',m=>{const p=panel(0);dcTitle(p,'2.68 + 1.57','Start with hundredths.');const b=dcBoard(p,{x:260,answer:['4','2','5']});dcText(p,'8 hundredths + 7 hundredths',1140,250,.2,28,COL.dim,'middle');const es=dcCells(p,15,870,335,m('combine'),10,26);es.slice(0,10).forEach((e,i)=>tw(e,{x:980,y:310+i*18},m('combine',3.9),3.2,io));es.slice(10).forEach((e,i)=>tw(e,{x:1170+i*26,y:445},m('combine',3.9),3.2,io));es.slice(0,10).forEach(e=>hide(e,m('exchange'),.3));dcPiece(p,980,310,18,180,m('exchange'));dcText(p,'1 tenth',990,555,m('exchange'),30,COL.task,'middle');dcText(p,'5 hundredths',1230,555,m('exchange'),30,COL.task,'middle');dcCarry(p,b,1,m('carry'));show(b.ans[2],m('carry'));dcText(p,'15 hundredths = 1 tenth + 5 hundredths',800,770,m('carry',1.5),34,COL.task,'middle');}],
['addtenths','Trade ten tenths',m=>{const p=panel(0);dcTitle(p,'6 tenths + 5 tenths + 1 carried tenth','Same whole unit; strips keep their sizes.');const b=dcBoard(p,{x:260,answer:['4','2','5']});dcCarry(p,b,1,.2);show(b.ans[2],.2);const es=dcStrips(p,12,850,340,m('combine'),28);es.slice(0,10).forEach((e,i)=>tw(e,{x:850+i*18},m('exchange')-1,1,io));es.slice(10).forEach((e,i)=>tw(e,{x:1180+i*30},m('exchange')-1,1,io));es.slice(0,10).forEach(e=>hide(e,m('exchange'),.2));dcSquare(p,850,340,m('exchange'));dcText(p,'1 whole',940,585,m('exchange'),30,COL.task,'middle');dcText(p,'2 tenths',1220,585,m('exchange'),30,COL.task,'middle');dcCarry(p,b,0,m('carry'));show(b.ans[1],m('carry'));show(b.ans[0],m('answer'));dcMath(p,'2.68 + 1.57 = 4.25',800,770,m('answer'),55);}],
['addunequal','Different decimal lengths',m=>{const p=panel(0);dcTitle(p,'8.4 + 0.675','Trailing zeros fill columns without changing the value.');const b=dcBoard(p,{x:340,step:180,places:['ones','tenths','hundredths','thousandths'],a:['8','4','',''],b:['0','6','7','5'],answer:['9','0','7','5']});['0','0'].forEach((v,i)=>{const e=dcText(p,v,b.xs[i+2],375,m('zeros'),58,COL.task,'middle');});show(b.ans[3],m('small',2.4));show(b.ans[2],m('small',6.2));dcCarry(p,b,0,m('carry',4.2));show(b.ans[1],m('carry',3));show(b.ans[0],m('answer'));dcText(p,'10 tenths = 1 whole + 0 tenths',800,675,m('carry'),30,COL.task,'middle','middle');dcMath(p,'9.075',800,760,m('answer'),62);}],
['q2','Quick check',()=>{const p=panel(0);dcTitle(p,'Which amount equals 7.3?','Same whole unit; strips and cells drawn at their exact relative sizes.');S.dcZero=[dcZeroPick(p,140,'7.30',1),dcZeroPick(p,640,'7.03',2),dcZeroPick(p,1140,'7.003',3)];},{ask:done=>quiz(BAND,[{id:'c-zeros',prompt:'Choose seven wholes and three TENTHS.',build:pickEls(S.dcZero,0,'7.30 equals 7.3. Thirty hundredths is three tenths. A trailing zero adds no value.',i=>i===1?'7.03 has three hundredths, not three tenths. The 3 moved to a smaller place.':'7.003 has three thousandths, not three tenths. The 3 moved two places.',()=>pulseFx(S.dcZero[0].el,1.02))}],done)}],
['subtract','Subtract matching places',m=>{const p=panel(0);dcTitle(p,'18.76 − 5.2','Keep same-sized places in the same columns.');const b=dcBoard(p,{x:275,step:125,places:['tens','ones','tenths','hundredths'],a:['1','8','7','6'],b:['','5','2',''],op:'−',answer:['1','3','5','6']});dcText(p,'0',b.xs[3],463,m('pad'),58,COL.task,'middle');dcAnswer(b,['1','3','5','6'],[m('right',8.8),m('right',7.7),m('right',5.1),m('right',2.4)]);dcMath(p,'18.76 − 5.20 = 13.56',1110,360,m('answer'),43);dcMath(p,'13.56 + 5.20 = 18.76',1110,525,m('check'),43);dcText(p,'Add back to check.',1110,600,m('check',1),32,COL.task,'middle');}],
['borrow','A zero column needs a bridge',m=>{const p=panel(0);dcTitle(p,'4.02 − 1.76','Trade 1 whole for 10 tenths.');const b=dcBoard(p,{x:260,a:['4','0','2'],b:['1','7','6'],op:'−'});dcText(p,'2 hundredths < 6 hundredths',1140,255,m('need'),29,COL.task,'middle');const whole=dcSquare(p,875,340),cells=dcCells(p,2,1240,340,.2,2,26);[1020,1100,1180].forEach(x=>{const o=G(p,{x:x-30,y:625,o:0});mk('rect',{width:60,height:60,fill:COL.chalk,'fill-opacity':.12,stroke:COL.chalk,'stroke-opacity':.5,'stroke-width':1.5},o);show(o,.2);});dcText(p,'3 other wholes stay in their column',1110,730,.2,28,COL.dim,'middle');dcText(p,'2 hundredths',1253,395,.2,26,COL.dim,'middle');hide(whole,m('whole'),.2);const es=dcStrips(p,10,875,340,m('whole'));es.forEach((e,i)=>tw(e,{x:840+i*31},m('whole',1.5),1.2,io));S.dcBorrowCounts=dcCount(p,b,[3,10,2],m('whole'));dcText(p,'1 whole → 10 tenths',1120,585,m('whole',1),34,COL.task,'middle');dcMath(p,'3 + 1.0 + 0.02 = 4.02',800,795,m('same'),44);}],
['borrowhund','Exchange a tenth, then subtract',m=>{const p=panel(0);dcTitle(p,'4.02 − 1.76','Three wholes stay in place; watch the fractional pieces.');const b=dcBoard(p,{x:260,a:['4','0','2'],b:['1','7','6'],op:'−',answer:['2','2','6']});const old=dcCount(p,b,[3,10,2],.2),es=dcStrips(p,10,840,325,.2,31),cells=dcCells(p,2,1240,325,.2,2,26);hide(es[9],m('tenth'),.2);const split=dcCells(p,10,1119,325,m('tenth'),1,18);split.forEach((e,i)=>tw(e,{x:920+(i%6)*26,y:565+Math.floor(i/6)*26},m('tenth',1.2),1.2,io));cells.forEach((e,i)=>tw(e,{x:1024+i*26,y:591},m('tenth',1.2),1.2,io));hide(old,m('twelve'),.2);dcCount(p,b,[3,9,12],m('twelve'));dcText(p,'9 tenths remain',975,270,m('twelve'),29,COL.task,'middle');dcText(p,'12 hundredths',1110,650,m('twelve'),29,COL.task,'middle');dcAnswer(b,['2','2','6'],[m('subtract',6),m('subtract',3),m('subtract')]);dcMath(p,'4.02 − 1.76 = 2.26',800,790,m('answer'),53);}],
['q3','Quick check',()=>{const p=panel(0);dcTitle(p,'Which regrouping still equals 4.02?','Choose counts that also let you remove 1 whole, 7 tenths and 6 hundredths.');S.dcRegroup=[[3,9,12],[3,10,12],[4,9,12]].map((ns,j)=>{const x=200+j*480,g=G(p);dcText(g,String.fromCharCode(65+j),x+135,270,.2,32,COL.dim,'middle');ns.forEach((n,i)=>{dcMath(g,String(n),x+130,350+i*100,.2,48);dcText(g,['wholes','tenths','hundredths'][i],x+180,350+i*100,.2,26,COL.dim);});return {el:g,box:[x-10,285,350,310],label:`${ns[0]} wholes, ${ns[1]} tenths, ${ns[2]} hundredths`};});},{ask:done=>quiz(BAND,[{id:'c-regroup',prompt:'Pick the counted pieces with the SAME total as the starting number.',build:pickEls(S.dcRegroup,0,'3 + 0.9 + 0.12 = 4.02. One whole became ten tenths, then one of those became ten hundredths.',i=>i===1?'3 + 1.0 + 0.12 = 4.12. Making ten hundredths must use up one tenth.':'4 + 0.9 + 0.12 = 5.02. Making ten tenths must use up one whole.',()=>pulseFx(S.dcRegroup[0].el,1.02))}],done)}],
['longzero','A longer zero bridge',m=>{const p=panel(0);dcTitle(p,'20 − 3.485','Regroup through every zero. Counts above digits always total 20.');const b=dcBoard(p,{x:290,step:190,places:['tens','ones','tenths','hundredths','thousandths'],a:['2','0','','',''],b:['','3','4','8','5'],op:'−',answer:['1','6','5','1','5']});[2,3,4].forEach(i=>dcText(p,'0',b.xs[i],375,m('pad'),58,COL.task,'middle'));const vectors=[[1,10,0,0,0],[1,9,10,0,0],[1,9,9,10,0],[1,9,9,9,10]],ks=['one','tenths','hundredths','thousandths'];let prev;vectors.forEach((v,i)=>{const g=dcCount(p,b,v,m(ks[i]));if(prev)hide(prev,m(ks[i]),.2);prev=g;});dcText(p,'1 larger unit → 10 of the next smaller unit',800,675,m('one'),33,COL.task,'middle');dcAnswer(b,['1','6','5','1','5'],[2.9,2.3,1.7,1.1,.5].map(o=>m('answer',o)));dcMath(p,'20.000 − 3.485 = 16.515',800,780,m('answer',4.8),54);}],
['money','Costs and change',m=>{const p=panel(0);dcTitle(p,'A museum trip · $40.00 budget','Whole dollars · tenths of a dollar · hundredths of a dollar');[['Ticket','$12.75'],['Meal','$8.60'],['Drink','$3.95']].forEach(([s,v],i)=>{dcText(p,s,130,345+i*100,.2,36,COL.dim);show(T(p,v,{x:660,y:345+i*100,size:56,font:MATH,anchor:'end',o:0}),.2);});path(p,'M120 590H680',{stroke:COL.chalk,'stroke-width':3});dcText(p,'Total',130,665,m('total'),36,COL.dim);show(T(p,'$25.30',{x:660,y:665,size:56,font:MATH,anchor:'end',fill:COL.task,o:0}),m('total',11.8));dcMath(p,'75 + 60 + 95 = 230 cents = $2.30',1110,360,m('total',3.5),40);dcMath(p,'$40.00 − $25.30 = $14.70',1110,560,m('left'),47);dcText(p,'First TWO decimal places count cents.',1110,740,m('cents'),32,COL.task,'middle');dcText(p,'Later places: fractions of a cent.',1110,795,m('cents',1),30,COL.dim,'middle');}],
['wrap','The four moves',m=>{const p=panel(0);[['Align decimal points: same-sized places meet.','w1'],['Trailing zeros fill empty places; value stays the same.','w2'],['Work right to left. Exchange pieces when needed.','w3'],['Drop the decimal point. Add back to check subtraction.','w4']].forEach(([s,k],i)=>{const g=G(p,{x:-16,y:245+i*145,o:0});mk('circle',{cx:150,cy:-10,r:26,fill:COL.task},g);T(g,String(i+1),{x:150,y:0,size:30,anchor:'middle',fill:COL.board});T(g,s,{x:215,size:34});tw(g,{x:0,o:1},m(k),.6);});}],
['final1','Chapter practice',()=>panel(0),{ask:done=>quiz(SCREEN,[{id:'p-add',prompt:'Add. Give the exact value; equivalent trailing zeros are accepted.',build:blanks([
{parts:['3.86 + 4.79 = ',{box:'8.65'}],why:'15 hundredths carries 1 tenth; 16 tenths carries 1 whole. The sum is 8.65.',hint:'Align decimal points and include each carried amount.'},
{parts:['12.047 + 3.6 = ',{box:'15.647'}],why:'Use 3.600 so tenths, hundredths and thousandths meet.'},
{parts:['9 + 0.825 = ',{box:'9.825'}],why:'Write 9.000. Nine wholes plus 825 thousandths is 9.825.'},
{parts:['2.35 + 0.8 + 14.006 = ',{box:'17.156'}],why:'Align 2.350, 0.800 and 14.006. The exact sum is 17.156.'}
])}],done,'Chapter practice · set 1 of 3')}],
['final2','Chapter practice',()=>panel(0),{ask:done=>quiz(SCREEN,[{id:'p-subtract',prompt:'Subtract. Regroup through zeros when a column needs more pieces.',build:blanks([
{parts:['16.84 − 2.7 = ',{box:'14.14'}],why:'Use 2.70: subtract matching places.'},
{parts:['6.03 − 2.58 = ',{box:'3.45'}],why:'Regroup 6.03 as 5 wholes, 9 tenths, 13 hundredths. Subtract to get 3.45.',hint:'A zero tenths column needs a whole exchanged first.'},
{parts:['50 − 7.264 = ',{box:'42.736'}],why:'50.000 regrouped has 4 tens, 9 ones, 9 tenths, 9 hundredths and 10 thousandths.'},
{parts:['23.4001 − 0.0786 = ',{box:'23.3215'}],why:'Keep ten-thousandths aligned. Regroup through both zero columns: the difference is 23.3215.'}
])}],done,'Chapter practice · set 2 of 3')}],
['final3','Chapter practice',()=>panel(0),{ask:done=>quiz(SCREEN,[
{id:'p-measure',prompt:'A 5.2-meter cable has a 3.875-meter piece removed. How much remains?',build:blanks([{parts:[{box:'1.325'},' meters'],why:'5.200 − 3.875 = 1.325. Check: 3.875 + 1.325 = 5.200.'}])},
{id:'p-money',prompt:'You have $20. A notebook costs $7.85, a pen set $4.60, and a folder $2.95. Find the total and money left.',build:blanks([{parts:['Total: $',{box:'15.40'}],why:'7.85 + 4.60 + 2.95 = 15.40. For money display $15.40.'},{parts:['Money left: $',{box:'4.60'}],why:'20.00 − 15.40 = 4.60. For money display $4.60.'}])},
{id:'p-identity',prompt:'Fill the blank with the same value. Trailing zeros are accepted.',build:blanks([{parts:['6.4 = ',{box:'6.400'}],why:'6.400 keeps the 4 in the tenths place and adds zero hundredths and thousandths.',hint:'You can add trailing zeros: 6.400 has the same value.'}])}
],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>