Skill: decimals-intro
Introducing Decimals Practice
Place value, fraction-decimal conversions, digit-by-digit comparisons, and money decimals.
How to enter answers
- Decimals: type
0.75(trailing zeros optional). - Fractions: type
7/20, in simplest form. - Comparisons: type
<,>, or=.
Problem types
Place value
What is the digit worth?
Example: the 2 in 5.28 → 0.2
Compare decimals
Digit by digit from the left.
Example: 0.6 __ 0.59 → >
Fraction to decimal
Rename as tenths or hundredths.
Example: 3/4 → 0.75
Decimal to fraction
Read it, write it, simplify.
Example: 0.35 → 7/20
Greatest decimal
Compare three at once.
Example: greatest of 0.4, 0.37, 0.402 → 0.402
Money decimals
Cents are hundredths of a dollar.
Example: 125 cents → $1.25
Common slip-ups
Longer means bigger
0.59 is not bigger than 0.6. Compare the tenths first: 6 > 5.
Misnaming the place
The first digit after the point is tenths, the second hundredths. Name it before writing the value.
Forgetting to simplify
0.35 = 35/100 must finish as 7/20.
/* ===== Fibo elementary core — skill: decimals-intro — pure, node-testable ===== */ (function (root, factory) { 'use strict'; var api = factory(); if (typeof module === 'undefined') { root.FiboCore_decimals_intro = api; } else { module.exports = api; } })(typeof self !== 'undefined' ? self : this, function () { 'use strict'; /* ---------------- seeded PRNG ---------------- */ function mulberry32(a){ return function(){ a |= 0; a = (a + 0x6D2B79F5) | 0; var t = Math.imul(a ^ (a >>> 15), 1 | a); t = (t + Math.imul(t ^ (t >>> 7), 61 | t)) ^ t; return ((t ^ (t >>> 14)) >>> 0) / 4294967296; }; } function shuffle(arr, rand){ for (var i = arr.length - 1; i > 0; i--){ var j = Math.floor(rand() * (i + 1)); var t = arr[i]; arr[i] = arr[j]; arr[j] = t; } return arr; } var _rand = Math.random; function setSeed(s){ _rand = mulberry32(s >>> 0); } function ri(lo, hi){ return lo + Math.floor(_rand() * (hi - lo + 1)); } function rpick(arr){ return arr[Math.floor(_rand() * arr.length)]; } function rchance(p){ return _rand() < p; } function rshuffle(a){ for (var i = a.length - 1; i > 0; i--){ var j = Math.floor(_rand() * (i + 1)); var t = a[i]; a[i] = a[j]; a[j] = t; } return a; } /* ---------------- exact integer / rational math ---------------- */ function ggcd(a, b){ a = Math.abs(a); b = Math.abs(b); while (b){ var t = a % b; a = b; b = t; } return a || 1; } function gred(n, d){ if (d === 0) throw new Error('gred: zero denominator'); if (d < 0){ n = -n; d = -d; } if (n === 0) return { n: 0, d: 1 }; var g = ggcd(n, d); return { n: n / g, d: d / g }; } function sameFrac(a, b){ return a.n * b.d === b.n * a.d; } /* exact decimal as {v: integer digits, p: places} */ function decVal(d){ return d.v / Math.pow(10, d.p); } function decNorm(d){ var v = d.v, p = d.p; while (p > 0){ if (v % 10 !== 0) break; v = v / 10; p = p - 1; } return { v: v, p: p }; } function decAdd(a, b){ var p = Math.max(a.p, b.p); var va = a.v * Math.pow(10, p - a.p); var vb = b.v * Math.pow(10, p - b.p); return decNorm({ v: va + vb, p: p }); } function decSub(a, b){ var p = Math.max(a.p, b.p); var va = a.v * Math.pow(10, p - a.p); var vb = b.v * Math.pow(10, p - b.p); return decNorm({ v: va - vb, p: p }); } function decTextFromVP(v, p){ var neg = v < 0; var s = String(Math.abs(v)); while (s.length <= p) s = '0' + s; var out; if (p === 0) out = s; else out = s.slice(0, s.length - p) + '.' + s.slice(s.length - p); if (neg) out = '-' + out; return out; } function decText(v){ var r = Math.round(v * 1e6) / 1e6; var s = String(r); if (s.indexOf('.') < 0) return s; s = s.replace(/0+$/, '').replace(/\.$/, ''); if (s === '-0') s = '0'; return s; } /* ---------------- formatting (HTML) ---------------- */ function fracHTML(n, d){ var r = gred(n, d); var sign = r.n < 0 ? '−' : ''; if (r.d === 1) return '' + sign + Math.abs(r.n) + ''; return sign + '' + Math.abs(r.n) + '' + r.d + ''; } function mixedHTML(w, n, d){ var r = gred(n, d); if (r.n === 0) return '' + w + ''; return '' + w + ' ' + fracHTML(r.n, r.d); } function intHTML(v){ return '' + v + ''; } function qrHTML(q, r){ if (r === 0) return '' + q + ''; return '' + q + ' R ' + r + ''; } function ansHTML(ans){ if (ans.kind === 'int') return intHTML(ans.v); if (ans.kind === 'frac') return fracHTML(ans.n, ans.d); if (ans.kind === 'mixed') return mixedHTML(ans.w, ans.n, ans.d); if (ans.kind === 'dec') return '' + decText(ans.v) + ''; if (ans.kind === 'qr') return qrHTML(ans.q, ans.r); if (ans.kind === 'cmp') return '' + (ans.c === '<' ? '<' : (ans.c === '>' ? '>' : '=')) + ''; if (ans.kind === 'yesno') return '' + (ans.v ? 'Yes' : 'No') + ''; if (ans.kind === 'parts') return '' + ans.parts.join(' + ') + ''; return '?'; } function ansText(ans){ if (ans.kind === 'int') return String(ans.v); if (ans.kind === 'frac'){ var r = gred(ans.n, ans.d); return r.d === 1 ? String(r.n) : r.n + '/' + r.d; } if (ans.kind === 'mixed'){ var g = gred(ans.n, ans.d); if (g.n === 0) return String(ans.w); var f = g.d === 1 ? String(ans.w + g.n) : ans.w + ' ' + g.n + '/' + g.d; return f; } if (ans.kind === 'dec') return decText(ans.v); if (ans.kind === 'qr') return ans.r === 0 ? String(ans.q) : ans.q + ' R ' + ans.r; if (ans.kind === 'cmp') return ans.c; if (ans.kind === 'yesno') return ans.v ? 'yes' : 'no'; if (ans.kind === 'parts') return ans.parts.join(' + '); return ''; } /* ---------------- input parsing ---------------- */ function parseIntInput(raw){ var t = String(raw).trim().replace(/,/g, ''); if (!/^[+-]?\d+$/.test(t)) return { ok: false }; return { ok: true, kind: 'int', v: parseInt(t, 10) }; } function parseFracInput(raw){ var t = String(raw).trim().replace(/\s+/g, ''); var m = t.match(/^([+-]?\d+)\/(\d+)$/); if (m){ var d = parseInt(m[2], 10); if (d === 0) return { ok: false }; var r = gred(parseInt(m[1], 10), d); return { ok: true, kind: 'frac', n: r.n, d: r.d }; } var iv = parseIntInput(raw); if (iv.ok) return { ok: true, kind: 'frac', n: iv.v, d: 1 }; return { ok: false }; } function parseMixedInput(raw){ var t = String(raw).trim().replace(/\s+/g, ' '); var m = t.match(/^(\d+)\s+(\d+)\/(\d+)$/); if (m){ var w = parseInt(m[1], 10), n = parseInt(m[2], 10), d = parseInt(m[3], 10); if (d === 0) return { ok: false }; if (n >= d) return { ok: false }; var r = gred(n, d); return { ok: true, kind: 'mixed', w: w, n: r.n, d: r.d }; } var f = parseFracInput(raw); if (f.ok) return f; return { ok: false }; } function parseDecInput(raw){ var t = String(raw).trim().replace(/,/g, '').replace(/^\$/, ''); if (!/^[+-]?(\d+(\.\d*)?|\.\d+)$/.test(t)) return { ok: false }; return { ok: true, kind: 'dec', v: parseFloat(t) }; } function parseCmpInput(raw){ var t = String(raw).trim().toLowerCase(); if (t === '<' || t === 'less' || t === 'less than' || t === 'smaller') return { ok: true, kind: 'cmp', v: -1 }; if (t === '>' || t === 'greater' || t === 'greater than' || t === 'bigger' || t === 'larger') return { ok: true, kind: 'cmp', v: 1 }; if (t === '=' || t === '==' || t === 'equal' || t === 'equals' || t === 'same') return { ok: true, kind: 'cmp', v: 0 }; return { ok: false }; } function parseYesNo(raw){ var t = String(raw).trim().toLowerCase(); if (t === 'yes' || t === 'y') return { ok: true, kind: 'yesno', v: true }; if (t === 'no' || t === 'n') return { ok: true, kind: 'yesno', v: false }; return { ok: false }; } function parseQRInput(raw){ var t = String(raw).trim().toLowerCase().replace(/remainder/g, 'r'); var parts = t.split(/[^0-9]+/); var nums = []; for (var i = 0; i < parts.length; i++){ if (parts[i] !== '') nums.push(parseInt(parts[i], 10)); } if (nums.length === 1) return { ok: true, kind: 'qr', q: nums[0], r: 0 }; if (nums.length === 2) return { ok: true, kind: 'qr', q: nums[0], r: nums[1] }; return { ok: false }; } function parsePartsInput(raw){ var t = String(raw).trim().toLowerCase().replace(/plus|and/g, '+'); var chunks = t.split(/[^0-9]+/); var parts = []; for (var i = 0; i < chunks.length; i++){ if (chunks[i] !== '') parts.push(parseInt(chunks[i], 10)); } if (parts.length === 0) return { ok: false }; return { ok: true, kind: 'parts', parts: parts }; } function parseByKind(kind, raw){ if (kind === 'int') return parseIntInput(raw); if (kind === 'frac') return parseFracInput(raw); if (kind === 'mixed') return parseMixedInput(raw); if (kind === 'dec') return parseDecInput(raw); if (kind === 'cmp') return parseCmpInput(raw); if (kind === 'yesno') return parseYesNo(raw); if (kind === 'qr') return parseQRInput(raw); if (kind === 'parts') return parsePartsInput(raw); return { ok: false }; } function entryHintFor(kind){ if (kind === 'int') return 'Enter a whole number, e.g. 42.'; if (kind === 'frac') return 'Enter a fraction like 3/4 (a whole number is fine too).'; if (kind === 'mixed') return 'Enter a mixed number like 2 1/3, or an improper fraction like 7/3.'; if (kind === 'dec') return 'Enter a decimal like 0.75.'; if (kind === 'cmp') return 'Enter <, >, or = (you can also type "less", "greater", or "equal").'; if (kind === 'yesno') return 'Enter yes or no.'; if (kind === 'qr') return 'Enter the quotient and remainder like 7 R 2.'; if (kind === 'parts') return 'Enter the partial products separated by +, e.g. 120 + 30.'; return 'Type your answer.'; } /* ---------------- answer checking ---------------- */ function ratOf(ans){ if (ans.kind === 'int') return { n: ans.v, d: 1 }; if (ans.kind === 'frac') return { n: ans.n, d: ans.d }; if (ans.kind === 'mixed') return { n: ans.w * ans.d + ans.n, d: ans.d }; return null; } function checkAnswer(exp, parsed){ if (!parsed.ok) return false; if (exp.kind === 'int') return !(!(parsed.kind === 'int') || !(parsed.v === exp.v)); if (exp.kind === 'qr') return !(!(parsed.kind === 'qr') || !(parsed.q === exp.q) || !(parsed.r === exp.r)); if (exp.kind === 'cmp'){ if (parsed.kind !== 'cmp') return false; var ev = exp.c === '<' ? -1 : (exp.c === '>' ? 1 : 0); return parsed.v === ev; } if (exp.kind === 'yesno') return !(!(parsed.kind === 'yesno') || !(parsed.v === exp.v)); if (exp.kind === 'parts'){ if (parsed.kind !== 'parts') return false; if (parsed.parts.length !== exp.parts.length) return false; var a = exp.parts.slice().sort(function(x, y){ return x - y; }); var b = parsed.parts.slice().sort(function(x, y){ return x - y; }); for (var i = 0; i < a.length; i++) if (a[i] !== b[i]) return false; return true; } if (exp.kind === 'dec'){ if (parsed.kind !== 'dec') return false; var dd = parsed.v - exp.v; if (dd < 0) dd = -dd; return dd < 1e-9; } var e = ratOf(exp); if (!e) return false; if (parsed.kind === 'frac' || parsed.kind === 'int' || parsed.kind === 'mixed'){ return sameFrac(e, ratOf(parsed)); } if (parsed.kind === 'dec'){ var dv = parsed.v - e.n / e.d; if (dv < 0) dv = -dv; return dv < 1e-9; } return false; } /* ---------------- per-skill question templates ---------------- */ function _dSteps(items){ var h = '
- ';
for (var i = 0; i < items.length; i++) h += '
- ' + items[i] + '
'; return h + '
'; } function _dWhy(steps, ansHTML){ return _dSteps(steps) + '
'; } function _dgcd(a, b){ while (b){ var t = a % b; a = b; b = t; } return a; } function _dstr(x){ var s = (Math.round(x * 1000) / 1000).toFixed(3).replace(/0+$/, '').replace(/\.$/, ''); return s; } function _dcmp(a, b){ return a < b ? '<' : (a > b ? '>' : '='); } var TEMPLATES = [ { id: 'P1', tag: 'Place value', level: 0, enumerate: function(){ var out = []; for (var w = 1; w <= 9; w++) for (var t = 1; t <= 9; t++) for (var h = 0; h <= 9; h++){ if (t === h) continue; out.push({ key: 'p' + w + t + h + 't', w: w, t: t, h: h, place: 'tenths', v: t / 10 }); if (h > 0) out.push({ key: 'p' + w + t + h + 'h', w: w, t: t, h: h, place: 'hundredths', v: h / 100 }); } return out; }, make: function(p){ var num = p.w + '.' + p.t + p.h; var digit = p.place === 'tenths' ? p.t : p.h; return { promptHTML: 'In ' + num + ', what is the ' + digit + ' worth? (Type the decimal value.)', answer: { kind: 'dec', v: p.v }, hintHTML: 'The ' + digit + ' is in the ' + p.place + ' place.', whyHTML: _dWhy([ 'The ' + p.place + ' place is worth ' + (p.place === 'tenths' ? '0.1' : '0.01') + ' per unit.', digit + ' × ' + (p.place === 'tenths' ? '0.1' : '0.01') + ' = ' + _dstr(p.v) + '.' ], '' + _dstr(p.v) + '') }; } }, { id: 'P2', tag: 'Compare decimals', level: 0, enumerate: function(){ var out = []; for (var a = 1; a <= 99; a++) for (var b = 1; b <= 99; b++){ if (a !== b) out.push({ key: 'c' + a + 'v' + b, a: a / 100, b: b / 100 }); } return out; }, make: function(p){ var c = _dcmp(p.a, p.b); return { promptHTML: 'Compare: ' + _dstr(p.a) + ' __ ' + _dstr(p.b) + '. Type <, >, or =.', answer: { kind: 'cmp', c: c }, hintHTML: 'Line up the points; compare the tenths first.', whyHTML: _dWhy([ 'Tenths: ' + Math.floor(p.a * 10) + ' vs ' + Math.floor(p.b * 10) + (Math.floor(p.a * 10) !== Math.floor(p.b * 10) ? ' → decided here.' : '; then hundredths: ' + Math.floor(p.a * 100 % 10) + ' vs ' + Math.floor(p.b * 100 % 10) + '.'), _dstr(p.a) + ' ' + c + ' ' + _dstr(p.b) + '.' ], '' + c + '') }; } }, { id: 'P3', tag: 'Fraction to decimal', level: 1, enumerate: function(){ var out = []; var denoms = [2, 4, 5, 8, 10, 20, 25, 50]; for (var i = 0; i < denoms.length; i++){ var d = denoms[i]; for (var n = 1; n < d; n++){ var v = n / d; if (Math.round(v * 1000) === v * 1000) out.push({ key: 'f' + n + 'd' + d, n: n, d: d, v: v }); } } return out; }, make: function(p){ return { promptHTML: 'Write ' + p.n + '/' + p.d + ' as a decimal.', answer: { kind: 'dec', v: p.v }, hintHTML: 'Rename as hundredths or thousandths, then read the places.', whyHTML: _dWhy([ p.n + '/' + p.d + ' = ' + Math.round(p.v * 1000) + '/1000.', 'Read as a decimal: ' + _dstr(p.v) + '.' ], '' + _dstr(p.v) + '') }; } }, { id: 'P4', tag: 'Decimal to fraction', level: 1, enumerate: function(){ var out = []; for (var t = 1; t <= 9; t++) for (var h = 0; h <= 9; h++){ var hund = t * 10 + h; var g = _dgcd(hund, 100); out.push({ key: 'd' + t + h, t: t, h: h, sn: hund / g, sd: 100 / g, v: hund / 100 }); } return out; }, make: function(p){ var dec = _dstr(p.v); return { promptHTML: 'Write ' + dec + ' as a fraction in simplest form.', answer: { kind: 'frac', n: p.sn, d: p.sd }, hintHTML: 'Read it: ' + dec + ' = ? hundredths. Then simplify.', whyHTML: _dWhy([ dec + ' = ' + (p.t * 10 + p.h) + '/100.', 'Simplify by dividing by ' + _dgcd(p.t * 10 + p.h, 100) + ': ' + p.sn + '/' + p.sd + '.' ], '' + p.sn + '/' + p.sd + '') }; } }, { id: 'P5', tag: 'Greatest decimal', level: 2, enumerate: function(){ var out = []; for (var a = 5; a <= 95; a += 7) for (var b = a + 3; b <= 98; b += 11) for (var c = 10; c <= 90; c += 13){ var vs = [a / 100, b / 100, c / 100]; if (!(vs[0] === vs[1] || vs[1] === vs[2] || vs[0] === vs[2])) out.push({ key: 'g' + a + b + c, vs: vs }); } return out; }, make: function(p){ var m = Math.max(p.vs[0], p.vs[1], p.vs[2]); var list = p.vs.map(_dstr).join(', '); return { promptHTML: 'Which is the greatest: ' + list + '?', answer: { kind: 'dec', v: m }, hintHTML: 'Compare the tenths first; break ties with the hundredths.', whyHTML: _dWhy([ 'Tenths: ' + p.vs.map(function(v){ return Math.floor(v * 10); }).join(', ') + '.', 'The greatest is ' + _dstr(m) + '.' ], '' + _dstr(m) + '') }; } }, { id: 'P6', tag: 'Money decimals', level: 1, enumerate: function(){ var out = []; for (var c = 1; c <= 500; c += 7) out.push({ key: 'm' + c, c: c, v: c / 100 }); return out; }, make: function(p){ return { promptHTML: 'Write ' + p.c + ' cents as dollars. (Type the decimal, like 1.25.)', answer: { kind: 'dec', v: p.v }, hintHTML: '100 cents = 1 dollar. Cents are hundredths.', whyHTML: _dWhy([ p.c + ' ÷ 100 = ' + _dstr(p.v) + '.', 'That is $' + _dstr(p.v) + '.' ], '' + _dstr(p.v) + '') }; } } ];
/* ---------------- practice session ---------------- */ function PracticeSession(seed){ this._rand = mulberry32(seed >>> 0); this.pools = {}; this.seen = {}; this.score = 0; this.streak = 0; this.problemNum = 0; this.current = null; this.wrongCount = 0; this.revealed = false; this._done = false; } PracticeSession.prototype._draw = function (){ var guard, t, pool, p, key, prob; for (guard = 0; guard < 200; guard++){ t = TEMPLATES[Math.floor(this._rand() * TEMPLATES.length)]; pool = this.pools[t.id]; if (!pool || pool.length === 0){ pool = shuffle(t.enumerate().slice(), this._rand); this.pools[t.id] = pool; } p = pool.pop(); key = t.id + '|' + p.key; if (this.seen[key]) continue; this.seen[key] = 1; prob = t.make(p); prob.templateId = t.id; prob.tag = t.tag; prob.key = key; prob.params = p; prob.answerDisplayHTML = ansHTML(prob.answer); prob.accept = [ansText(prob.answer)]; return prob; } this.pools = {}; this.seen = {}; t = TEMPLATES[0]; p = t.enumerate()[0]; prob = t.make(p); prob.templateId = t.id; prob.tag = t.tag; prob.key = t.id + '|' + p.key; prob.params = p; prob.answerDisplayHTML = ansHTML(prob.answer); prob.accept = [ansText(prob.answer)]; return prob; }; PracticeSession.prototype.next = function (){ this.current = this._draw(); this.wrongCount = 0; this.revealed = false; this._done = false; this.problemNum++; return this.current; }; PracticeSession.prototype.submit = function (raw){ var pr = this.current; if (!pr) return { status: 'none' }; if (this._done) return { status: 'already' }; var parsed = parseByKind(pr.answer.kind, raw); if (!parsed.ok) return { status: 'invalid', entryHint: entryHintFor(pr.answer.kind) }; var ok = checkAnswer(pr.answer, parsed); if (ok){ this._done = true; var firstTry = !(!(this.wrongCount === 0) || this.revealed); if (!this.revealed){ this.streak++; if (firstTry) this.score++; } return { status: 'correct', firstTry: firstTry, score: this.score, streak: this.streak, answerHTML: pr.answerDisplayHTML }; } this.wrongCount++; this.streak = 0; if (this.wrongCount === 1) return { status: 'hint', hintHTML: pr.hintHTML, streak: 0 }; this.revealed = true; return { status: 'why', whyHTML: pr.whyHTML, streak: 0 }; }; PracticeSession.prototype.reveal = function (){ if (!this.current) return null; this.revealed = true; return this.current.whyHTML; }; /* ---------------- game API (wraps the same templates) ---------------- */ var _gameKind = 'int'; function difficultyFor(qi){ if (qi < 5) return 0; if (qi < 12) return 1; return 2; } function genQuestion(rng, asked, qIndex){ var diff = difficultyFor(qIndex); var elig = []; var i, t; for (i = 0; i < TEMPLATES.length; i++){ if (TEMPLATES[i].level <= diff) elig.push(TEMPLATES[i]); } if (elig.length === 0) elig = TEMPLATES; for (var tries = 0; tries < 80; tries++){ t = elig[Math.floor(rng() * elig.length)]; var pool = t.enumerate(); var p = pool[Math.floor(rng() * pool.length)]; var key = t.id + '|' + p.key; if (asked[key]) continue; asked[key] = 1; var prob = t.make(p); _gameKind = prob.answer.kind; return { typeLabel: t.tag, prompt: prob.promptHTML, correct: prob.answer, why: prob.whyHTML, answerDisplayHTML: ansHTML(prob.answer) }; } t = elig[0]; var p0 = t.enumerate()[0]; var pr0 = t.make(p0); _gameKind = pr0.answer.kind; return { typeLabel: t.tag, prompt: pr0.promptHTML, correct: pr0.answer, why: pr0.whyHTML, answerDisplayHTML: ansHTML(pr0.answer) }; } function gameParseAnswer(raw){ return parseByKind(_gameKind, raw); } function gameAnswerEquals(correct, parsed){ return checkAnswer(correct, parsed); } function gameAnswerText(correct){ return ansText(correct); } function gameAnswerHintText(){ return entryHintFor(_gameKind); } function newGameState(){ return { score: 0, streak: 0, bestStreak: 0, lives: 3, timeLeft: 60, qIndex: 0, answered: 0, correct: 0, over: false, overReason: '' }; } function tickTimer(s){ if (s.timeLeft > 0) s.timeLeft--; if (s.timeLeft <= 0){ s.over = true; s.overReason = 'time'; return true; } return false; } function scoreStep(s, ok){ s.answered++; if (ok){ s.correct++; s.streak++; if (s.streak > s.bestStreak) s.bestStreak = s.streak; var pts = 10; if (s.streak >= 4) pts += 2 * (s.streak - 3); s.score += pts; return { points: pts, gameOver: false }; } s.streak = 0; s.lives--; var over = s.lives <= 0; if (over){ s.over = true; s.overReason = 'lives'; } return { points: 0, gameOver: over }; } function accuracyPct(s){ if (s.answered === 0) return 0; return Math.round(s.correct / s.answered * 100); } /* ---------------- worksheet generation ---------------- */ function _wgcd9(a, b){ while (b){ var t = a % b; a = b; b = t; } return a; } function _wdstr(x){ var s = (Math.round(x * 1000) / 1000).toFixed(3).replace(/0+$/, '').replace(/\.$/, ''); return s; } function wgPlace(){ var w = ri(1, 9), t = ri(1, 9), h = ri(0, 9); if (h === t) h = (h + 1) % 10; var tenths = Math.random() < 0.5; var digit = tenths ? t : h; var v = tenths ? t / 10 : h / 100; if (!tenths){ if (h === 0){ h = ri(1, 9); if (h === t) h = h % 9 + 1; v = h / 100; digit = h; } } return { kind: 'place', params: { w: w, t: t, h: h }, stemHTML: 'In ' + w + '.' + t + h + ', what is the ' + digit + ' worth?', answerHTML: '' + _wdstr(v) + '', answer: { kind: 'dec', v: v } }; } function wgCmpDec(){ var a = ri(1, 99) / 100, b = ri(1, 99) / 100; if (a === b) b = (ri(1, 99) / 100 + 0.01) % 1; var c = a < b ? '<' : '>'; return { kind: 'cmpdec', params: { a: a, b: b }, stemHTML: 'Compare: ' + _wdstr(a) + ' __ ' + _wdstr(b) + '. Type <, >, or =.', answerHTML: '' + c + '', answer: { kind: 'cmp', c: c } }; } function wgF2D(){ var denoms = [2, 4, 5, 8, 10, 20, 25, 50]; var d = denoms[ri(0, denoms.length - 1)], n = ri(1, d - 1); var v = n / d; return { kind: 'f2d', params: { n: n, d: d }, stemHTML: 'Write ' + n + '/' + d + ' as a decimal.', answerHTML: '' + _wdstr(v) + '', answer: { kind: 'dec', v: v } }; } function wgD2F(){ var t = ri(1, 9), h = ri(0, 9); var hund = t * 10 + h, g = _wgcd9(hund, 100); return { kind: 'd2f', params: { t: t, h: h }, stemHTML: 'Write ' + _wdstr(hund / 100) + ' as a fraction in simplest form.', answerHTML: '' + (hund / g) + '/' + (100 / g) + '', answer: { kind: 'frac', n: hund / g, d: 100 / g } }; } var WSGENS = { easy: [wgPlace, wgPlace, wgCmpDec], medium: [wgPlace, wgCmpDec, wgF2D, wgD2F], hard: [wgF2D, wgD2F, wgCmpDec, wgF2D] };
function generateSet(seed, diff){ setSeed(seed); var gens = WSGENS[diff] || WSGENS.medium; var probs = [], seen = {}, guard = 0; while (!(!(probs.length < 20) || !(guard < 600))){ guard++; var g = gens[Math.floor(_rand() * gens.length)]; var pr = g(); if (seen[pr.stemHTML]) continue; seen[pr.stemHTML] = 1; probs.push(pr); } return probs; } /* ---------------- expose ---------------- */ var API = { PracticeSession: PracticeSession, TEMPLATES: TEMPLATES, WSGENS: WSGENS, generateSet: generateSet, genQuestion: genQuestion, difficultyFor: difficultyFor, parseAnswer: gameParseAnswer, parseByKind: parseByKind, parsePartsInput: parsePartsInput, parseQRInput: parseQRInput, answerEquals: gameAnswerEquals, answerText: gameAnswerText, answerHintText: gameAnswerHintText, newGameState: newGameState, scoreStep: scoreStep, tickTimer: tickTimer, accuracyPct: accuracyPct, mulberry32: mulberry32, setSeed: setSeed, ggcd: ggcd, gred: gred, sameFrac: sameFrac, decVal: decVal, decNorm: decNorm, decAdd: decAdd, decSub: decSub, decText: decText, decTextFromVP: decTextFromVP, fracHTML: fracHTML, mixedHTML: mixedHTML, ansHTML: ansHTML, ansText: ansText, checkAnswer: checkAnswer }; return API; });
/* ===== page glue: wires the tested core to the DOM (generic) ===== */ (function () { 'use strict'; var CORE = window.FiboCore_decimals_intro; var PLACEHOLDERS = {dec:'e.g. 0.75', frac:'e.g. 7/20', cmp:'<, >, or ='}; var session = new CORE.PracticeSession((Date.now() % 2000000000) + 7); function el(id) { return document.getElementById(id); } var input = el('ansInput'), checkBtn = el('checkBtn'), anotherBtn = el('anotherBtn'), showSolBtn = el('showSolBtn'), promptTag = el('promptTag'), promptEl = el('promptEl'), fb = el('fb'), hintBox = el('hintBox'), whyBox = el('whyBox'), statsLine = el('statsLine');
function updateStats() { statsLine.innerHTML = 'Score ' + session.score + ' · Streak ' + session.streak + ' · Problem ' + session.problemNum + ''; } function clearPanels() { fb.className = 'fb'; fb.innerHTML = ''; hintBox.className = 'hintbox'; hintBox.innerHTML = ''; whyBox.className = 'whybox'; whyBox.innerHTML = ''; } function showFb(kind, html) { fb.className = 'fb show ' + kind; fb.innerHTML = html; } function kindPlaceholder(kind) { return Object.prototype.hasOwnProperty.call(PLACEHOLDERS, kind) ? PLACEHOLDERS[kind] : 'Type your answer'; } function newProblem() { var pr = session.next(); promptTag.textContent = pr.tag; promptEl.innerHTML = pr.promptHTML; input.value = ''; input.placeholder = kindPlaceholder(pr.answer.kind); clearPanels(); showSolBtn.style.display = ''; updateStats(); input.focus(); } function showWhy() { whyBox.className = 'whybox show'; whyBox.innerHTML = '
' + session.current.whyHTML; showSolBtn.style.display = 'none'; } checkBtn.addEventListener('click', function () { var r = session.submit(input.value); updateStats(); if (r.status === 'invalid') { showFb('warn', 'Could not read that. ' + r.entryHint); return; } if (r.status === 'already' || r.status === 'none') return; if (r.status === 'correct') { if (r.firstTry) { showFb('ok', 'Correct! +1 point. The answer is ' + r.answerHTML + ''); } else if (session.revealed) { showFb('ok', 'That is right. You already saw the solution, so the streak is unchanged. ' + 'Hit Try another for a fresh problem.'); } else { showFb('ok', 'Correct! The answer is ' + r.answerHTML + ' ' + 'Solved after a hint, so no point this time — but the streak grows.'); } showSolBtn.style.display = 'none'; return; } if (r.status === 'hint') { showFb('no', 'Not quite. Try again — here is a hint.'); hintBox.className = 'hintbox show'; hintBox.innerHTML = r.hintHTML; input.focus(); input.select(); return; } if (r.status === 'why') { showFb('no', 'Not quite. Let us walk through it step by step.'); showWhy(); return; } }); anotherBtn.addEventListener('click', newProblem); showSolBtn.addEventListener('click', function () { session.reveal(); showWhy(); updateStats(); }); input.addEventListener('keydown', function (e) { if (e.key === 'Enter') checkBtn.click(); }); newProblem(); })();