${streak()} day streak · flashcard accuracy ${accuracy()}
Exam areas
${areaRows}
Mock exams draw questions in proportion to each area's share of the exam.
Topics
Topic
Cards
Learned
${famRows}
In the full version each card's likelihood is ranked from how often its topic is tested and the exam weight of its area. Here the sample cards carry a fixed likelihood.
Schedule
Introduce about ${perDay} new cards per day from ${fmt(S.startDate)}, most likely first. Review everything during the final week, starting ${fmt(reviewDay)}. Take a full mock exam each week.
Likelihood
Cards
Target dates
${planRows}
${plan.filter(c => !seen(c)).length} planned cards not started.
Box system
${boxCounts.map((n, i) => `
Box ${i + 1}${n}every ${BOX_DAYS[i]}d
`).join("")}
There are no grade buttons. Answer right and the card moves up a box; miss it and it goes back to box 1 and comes round again this session. Cards in box 5 and above count as learned. Missed mock-exam questions can be sent back to box 1.
`;
}
/* ---------- study ---------- */
// Conceptual cards recall a definition, rule or formula; calculation cards need working out a value.
const MODES = [["all", "All"], ["conceptual", "Conceptual"], ["calculation", "Calculation"]];
const modeOk = c => S.mode === "all" || c.mode === S.mode;
const modeLabel = c => c.mode === "calculation" ? "Calculation" : "Conceptual";
function modeTabs() {
return MODES.map(([id, name]) => {
const n = id === "all" ? CARDS.length : CARDS.filter(c => c.mode === id).length;
return ``;
}).join("");
}
function refreshModes() {
document.querySelectorAll("[data-modes]").forEach(el => el.innerHTML = modeTabs());
}
let browseDraw = () => {};
let queue = [], index = 0, flipped = false, picked = null;
function startSession() {
queue = [...dueCards(), ...newCardsToday()].map(c => c.id);
index = 0; flipped = false; picked = null; lastGrade = 0; gradeNote = "";
renderStudy();
}
function currentCard() { return BY_ID[queue[index]]; }
function renderStudy() {
const empty = document.getElementById("study-empty");
const active = document.getElementById("study-active");
refreshModes();
if (!queue.length || index >= queue.length) {
empty.classList.remove("hidden"); active.classList.add("hidden");
const scope = S.mode === "all" ? "" : ` in ${S.mode}`;
empty.innerHTML = queue.length
? `
Timed, multiple choice, one answer each, like the real CBT exam. The clock keeps running if you leave this tab, and the exam submits itself when time is up. In this demo, ${PASS_HIGH}% or better is on track.
Generated mock exams
${MOCKS.map(m => `
${m.name}
${m.blurb}
`).join("")}
History
${S.mocks.length ? `
Date
Exam
Score
By area
${hist}
`
: `
No mock exams yet.
`}
`;
}
const scoreClass = p => p >= PASS_HIGH ? "pass" : p >= PASS_LOW ? "edge" : "fail";
function renderRunner(root) {
const A = S.active, c = BY_ID[A.ids[A.idx]];
const answered = Object.keys(A.answers).length;
root.innerHTML = `
The schedule and review timing adjust to this date.
Daily new cards
Automatic: ${autoNewPerDay()} per day. Enter a number to override.
Theme
Backup
Progress and mock exam history stay in this browser only. Copy them to keep a backup, or import a saved file on another device.
About the cards
${CARDS.filter(isProblem).length} worked problems and ${CARDS.filter(c => !isProblem(c)).length} concept cards, all written for this demonstration and checked by recomputing every answer. The full version runs the same app on a much larger private deck.
Reset
Erases all card progress and mock exam history in this browser.
`;
document.getElementById("exam").addEventListener("change", e => { S.examDate = e.target.value; save(); render(); });
document.getElementById("exam-clear").onclick = () => { S.examDate = ""; save(); render(); };
document.getElementById("perday-save").onclick = () => {
const v = parseInt(document.getElementById("perday").value, 10);
S.newPerDay = v > 0 ? v : 0; save(); render();
};
document.getElementById("lowtier").onchange = e => { S.includeLow = e.target.checked; save(); render(); };
const savedTheme = (() => { try { return localStorage.getItem("surveying-theme") || ""; } catch (e) { return ""; } })();
const themeSel = document.getElementById("theme");
themeSel.value = savedTheme;
themeSel.onchange = () => {
try { localStorage.setItem("surveying-theme", themeSel.value); } catch (e) {}
applyTheme(themeSel.value);
};
document.getElementById("export").onclick = async e => {
const btn = e.currentTarget;
try { await navigator.clipboard.writeText(JSON.stringify(S)); btn.textContent = "Copied"; }
catch (err) { btn.textContent = "Copy failed"; }
setTimeout(() => { btn.textContent = "Copy progress"; }, 1600);
};
document.getElementById("import").onchange = async e => {
const f = e.target.files[0]; if (!f) return;
try {
const data = JSON.parse(await f.text());
if (!data || typeof data.cards !== "object") throw new Error("not a progress file");
S = Object.assign(freshState(), data, { v: 2 });
save(); render();
} catch (err) { tell("That file is not a valid progress file. Choose a file saved with Copy progress."); }
};
document.getElementById("reset").onclick = () => {
ask("Erase all progress and mock exam history in this browser? This can't be undone.", () => {
S = Object.assign(freshState(), { examDate: S.examDate });
examResult = null; save(); render();
}, "Erase");
};
}
function applyTheme(t) {
if (t) document.documentElement.setAttribute("data-theme", t);
else document.documentElement.removeAttribute("data-theme");
}
/* ---------- navigation ---------- */
const VIEWS = ["home", "study", "exam", "browse", "settings"];
let view = "home";
function show(v) {
view = v;
document.querySelectorAll("nav button").forEach(b => b.classList.toggle("on", b.dataset.view === v));
VIEWS.forEach(name => document.getElementById("view-" + name).classList.toggle("hidden", name !== v));
render();
window.scrollTo(0, 0);
}
function render() {
if (view !== "exam") { clearInterval(tick); tick = null; }
if (view === "home") renderHome();
if (view === "study") { if (!queue.length && index === 0) startSession(); else renderStudy(); }
if (view === "exam") renderExam();
if (view === "browse") renderBrowse();
if (view === "settings") renderSettings();
}
document.querySelectorAll("nav button").forEach(b => b.addEventListener("click", () => show(b.dataset.view)));
// Mode tabs appear in Study and Cards; the choice is shared, so both views follow it.
document.querySelector("main").addEventListener("click", e => {
const b = e.target.closest("[data-mode]"); if (!b) return;
S.mode = b.dataset.mode; save();
startSession();
browseDraw();
});
document.getElementById("view-home").addEventListener("click", e => {
const b = e.target.closest("[data-go]"); if (b) show(b.dataset.go);
});
document.getElementById("view-exam").addEventListener("click", e => {
const s = e.target.closest("[data-start]");
if (s) {
const go = () => { S.active = null; startExam(s.dataset.start); };
if (S.active) ask("Abandon the exam in progress?", go, "Abandon"); else go();
return;
}
const r = e.target.closest("[data-review]");
if (r) { examResult = S.mocks[+r.dataset.review]; renderExam(); window.scrollTo(0, 0); }
});
document.getElementById("flashcard").addEventListener("click", e => {
const b = e.target.closest("[data-choice]"); if (b) pick(+b.dataset.choice);
});
document.getElementById("reveal").addEventListener("click", flip);
document.getElementById("next").addEventListener("click", next);
document.addEventListener("keydown", e => {
if (["INPUT", "SELECT", "TEXTAREA"].includes(e.target.tagName) || e.ctrlKey || e.metaKey || e.altKey) return;
if (!document.getElementById("modal").classList.contains("hidden")) { if (e.key === "Escape") document.getElementById("modal-no").click(); return; }
const k = e.key.toUpperCase();
if (view === "study") {
if (e.code === "Space") { e.preventDefault(); flip(); }
else if (!flipped && "ABCDE".includes(k) && k.length === 1) pick(LETTERS.indexOf(k));
} else if (view === "exam" && S.active) {
const c = BY_ID[S.active.ids[S.active.idx]];
if ("ABCDE".includes(k) && k.length === 1 && LETTERS.indexOf(k) < c.c.length) { S.active.answers[c.id] = LETTERS.indexOf(k); save(); renderExam(); }
else if (e.key === "ArrowRight" && S.active.idx < S.active.ids.length - 1) { S.active.idx++; save(); renderExam(); }
else if (e.key === "ArrowLeft" && S.active.idx > 0) { S.active.idx--; save(); renderExam(); }
}
});
try { applyTheme(localStorage.getItem("surveying-theme") || ""); } catch (e) {}
// The header wraps on narrow screens; keep the exam timer bar just below it.
const setHdr = () => {
const h = document.querySelector("header");
document.documentElement.style.setProperty("--hdr", (getComputedStyle(h).position === "sticky" ? h.offsetHeight : 0) + "px");
};
window.addEventListener("resize", setHdr); setHdr();
show(S.active ? "exam" : "home");
// Bar widths are set here rather than in a style="" attribute, so the page works under the site's strict
// Content-Security-Policy (style-src 'self').
(function () {
const size = root => root.querySelectorAll('[data-w]').forEach(el => { el.style.width = el.dataset.w + '%'; });
size(document);
new MutationObserver(() => size(document)).observe(document.body, { childList: true, subtree: true });
})();