Skill: fractions-add-subtract
Bar Addition Lab
Add two fractions with bars: pick each fraction, see them renamed to a shared strip, and watch the total fill up.
Bar addition lab
Pick two fractions. The lab renames both to a shared strip of the LCD, then fills the total — watch wholes appear when the sum passes 1.
Try this
Add 3/4 + 1/2. How many fourths is the total? Where does the whole appear?
/* == PURE (tested by test_lab.js) == */
function lBarGcd(a, b){ while (b){ var t = a % b; a = b; b = t; } return a; }
function lBarAdd(n1, d1, n2, d2){
if (d1 < 1 || d2 < 1 || n1 < 0 || n1 > d1 || n2 < 0 || n2 > d2) return { ok: false };
var L = d1 / lBarGcd(d1, d2) * d2;
var tn = n1 * L / d1 + n2 * L / d2;
var g = lBarGcd(tn, L);
return { ok: true, lcd: L, r1n: n1 * L / d1, r2n: n2 * L / d2, tn: tn,
sn: tn / g, sd: L / g, wholes: Math.floor(tn / L), rem: tn % L };
}
/* == /PURE == */
/* == PURE (tested by test_lab.js) == */ function lBarGcd(a, b){ while (b){ var t = a % b; a = b; b = t; } return a; } function lBarAdd(n1, d1, n2, d2){ if (d1 < 1 || d2 < 1 || n1 < 0 || n1 > d1 || n2 < 0 || n2 > d2) return { ok: false }; var L = d1 / lBarGcd(d1, d2) * d2; var tn = n1 * L / d1 + n2 * L / d2; var g = lBarGcd(tn, L); return { ok: true, lcd: L, r1n: n1 * L / d1, r2n: n2 * L / d2, tn: tn, sn: tn / g, sd: L / g, wholes: Math.floor(tn / L), rem: tn % L }; } /* == /PURE == */
(function(){
'use strict';
function $(id){ return document.getElementById(id); }
function strip(n, d, y, w, fill, label){
var h = '
' + n1 + '/' + d1 + ' + ' + n2 + '/' + d2 + ' = ' + r.tn + '/' + r.lcd + ' = ' + r.sn + '/' + r.sd + '
'; } ['inN1', 'inD1', 'inN2', 'inD2'].forEach(function(id){ $(id).addEventListener('input', render); }); render(); })();