Parts V to IX in the book, extension 2.9.1, Demo topics
Add chapters 05-08 to the three language profiles: the published book stopped at Part IV because only 00-04 were listed. Rename the MQTT topic root Tutorial/ to Demo/ in Part IX (code and output included). Shared notes extension 2.9.1: dependency folders are named after the extension version, so browsers stop serving stale scripts after an update. Full rebuild of _book/ (HTML and PDF, three languages); remove the stray site_libs/ that the last Deploy commit had added at the project root. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
1 parent
01f681165f
commit
f047b9c7ae
128 files changed
+18893
-7591
No files matched your search
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
@@ -1,126 +0,0 @@
|
||||
// quiz — judge the tick boxes of one quiz, explain what went wrong
|
||||
//
|
||||
// Every label the reader sees is written into the markup by quiz.lua, so the
|
||||
// wording follows the book's language and nothing is translated twice. A
|
||||
// quiz carries:
|
||||
// data-quiz-score "{n} of {m} questions correct" ({n}/{m} substituted)
|
||||
// data-quiz-right verdict of a question answered correctly
|
||||
// data-quiz-wrong verdict of a question answered wrongly
|
||||
//
|
||||
// A question is right only when every one of its options is in the right
|
||||
// state: ticked when true, left empty when false. That is the "multiple
|
||||
// true/false" rule of the exam, and it is why a half-ticked question counts
|
||||
// as wrong.
|
||||
(function () {
|
||||
"use strict";
|
||||
|
||||
function options(quiz) {
|
||||
return quiz.querySelectorAll(".quiz-opt");
|
||||
}
|
||||
|
||||
function judge(quiz) {
|
||||
var questions = quiz.querySelectorAll(".quiz-q");
|
||||
var right = 0;
|
||||
|
||||
questions.forEach(function (q) {
|
||||
var ok = true;
|
||||
|
||||
q.querySelectorAll(".quiz-opt").forEach(function (opt) {
|
||||
var box = opt.querySelector(".quiz-box");
|
||||
if (!box) return;
|
||||
var want = opt.dataset.correct === "1";
|
||||
var hit = box.checked === want;
|
||||
|
||||
opt.classList.toggle("quiz-ok", hit);
|
||||
opt.classList.toggle("quiz-bad", !hit);
|
||||
|
||||
// the explanation of an option is for the reader who got it wrong
|
||||
var why = opt.querySelector(".quiz-why");
|
||||
if (why) why.hidden = hit;
|
||||
|
||||
if (!hit) ok = false;
|
||||
});
|
||||
|
||||
var verdict = q.querySelector(".quiz-verdict");
|
||||
if (verdict) {
|
||||
verdict.hidden = false;
|
||||
verdict.textContent = ok
|
||||
? (quiz.dataset.quizRight || "Correct")
|
||||
: (quiz.dataset.quizWrong || "Not quite");
|
||||
verdict.classList.toggle("quiz-ok", ok);
|
||||
verdict.classList.toggle("quiz-bad", !ok);
|
||||
}
|
||||
|
||||
// a question-level explanation backs up a wrong answer as a whole
|
||||
var qwhy = q.querySelector(".quiz-why-q");
|
||||
if (qwhy) qwhy.hidden = ok;
|
||||
|
||||
if (ok) right++;
|
||||
});
|
||||
|
||||
var score = quiz.querySelector(".quiz-score");
|
||||
if (score) {
|
||||
var template = quiz.dataset.quizScore || "{n}/{m}";
|
||||
score.innerHTML = "";
|
||||
// built as nodes, not markup: the template comes from metadata
|
||||
var parts = template.split(/\{n\}|\{m\}/);
|
||||
var values = [];
|
||||
(template.match(/\{n\}|\{m\}/g) || []).forEach(function (token) {
|
||||
values.push(token === "{n}" ? right : questions.length);
|
||||
});
|
||||
parts.forEach(function (text, i) {
|
||||
score.appendChild(document.createTextNode(text));
|
||||
if (i < values.length) {
|
||||
var b = document.createElement("b");
|
||||
b.textContent = String(values[i]);
|
||||
score.appendChild(b);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function reset(quiz) {
|
||||
options(quiz).forEach(function (opt) {
|
||||
var box = opt.querySelector(".quiz-box");
|
||||
if (box) box.checked = false;
|
||||
opt.classList.remove("quiz-ok", "quiz-bad");
|
||||
var why = opt.querySelector(".quiz-why");
|
||||
if (why) why.hidden = true;
|
||||
});
|
||||
quiz.querySelectorAll(".quiz-verdict").forEach(function (v) {
|
||||
v.hidden = true;
|
||||
v.textContent = "";
|
||||
v.classList.remove("quiz-ok", "quiz-bad");
|
||||
});
|
||||
quiz.querySelectorAll(".quiz-why-q").forEach(function (w) { w.hidden = true; });
|
||||
var score = quiz.querySelector(".quiz-score");
|
||||
if (score) score.textContent = "";
|
||||
}
|
||||
|
||||
document.addEventListener("click", function (event) {
|
||||
var target = event.target;
|
||||
if (!target.closest) return;
|
||||
|
||||
var check = target.closest(".quiz .quiz-check");
|
||||
if (check) {
|
||||
judge(check.closest(".quiz"));
|
||||
return;
|
||||
}
|
||||
var again = target.closest(".quiz .quiz-reset");
|
||||
if (again) {
|
||||
reset(again.closest(".quiz"));
|
||||
}
|
||||
});
|
||||
|
||||
// re-ticking a box after checking clears that row's verdict, so a stale
|
||||
// green or red never sits next to a box the reader has just changed
|
||||
document.addEventListener("change", function (event) {
|
||||
var box = event.target;
|
||||
if (!box.closest || !box.classList || !box.classList.contains("quiz-box")) return;
|
||||
var opt = box.closest(".quiz-opt");
|
||||
if (!opt) return;
|
||||
opt.classList.remove("quiz-ok", "quiz-bad");
|
||||
var why = opt.querySelector(".quiz-why");
|
||||
if (why) why.hidden = true;
|
||||
});
|
||||
})();
|
||||
+40
@@ -113,6 +113,31 @@
|
||||
margin-top: 0.5rem;
|
||||
}
|
||||
|
||||
/* ---- the per-question points badge ---------------------------------- */
|
||||
|
||||
/* The head now always exists (it is where the badge lands), so an empty one
|
||||
on a single-question quiz must not leave a gap. */
|
||||
.quiz-q-head:empty { display: none; }
|
||||
|
||||
.quiz-q-head {
|
||||
display: flex;
|
||||
align-items: baseline;
|
||||
justify-content: space-between;
|
||||
gap: 0.6rem;
|
||||
}
|
||||
|
||||
.quiz-q-score {
|
||||
font-size: 0.82rem;
|
||||
font-weight: 400;
|
||||
color: var(--quiz-ink);
|
||||
white-space: nowrap;
|
||||
}
|
||||
.quiz-q-score b { color: var(--calc-notecolor, #B45309); font-weight: 600; }
|
||||
/* green and red stay reserved for a judged answer; the badge follows the
|
||||
verdict right below it so the two never disagree */
|
||||
.quiz-q-score.quiz-ok b { color: var(--quiz-ok); }
|
||||
.quiz-q-score.quiz-bad b { color: var(--quiz-bad); }
|
||||
|
||||
/* ---- verdict and bar ------------------------------------------------ */
|
||||
|
||||
.quiz-verdict {
|
||||
@@ -160,6 +185,18 @@
|
||||
|
||||
/* ---- dark theme ----------------------------------------------------- */
|
||||
|
||||
/* High contrast remaps the whole palette, and --quiz-ok / --quiz-bad are local
|
||||
to this file, so they have to be pointed at the HC pair by hand: without
|
||||
this the verdict and the points badge keep their ordinary-mode green and
|
||||
red, which is exactly what a reader turns HC on to avoid. `body` makes it
|
||||
outweigh body.quarto-dark .quiz below, or dark + HC would keep the plain
|
||||
dark pair. */
|
||||
html.hc body .quiz {
|
||||
--quiz-ok: var(--hc-success);
|
||||
--quiz-bad: var(--hc-danger);
|
||||
--quiz-ink: var(--hc-fg);
|
||||
}
|
||||
|
||||
body.quarto-dark .quiz {
|
||||
--quiz-ok: #4cb08a;
|
||||
--quiz-bad: #e2798f;
|
||||
@@ -174,5 +211,8 @@ body.quarto-dark .quiz {
|
||||
*/
|
||||
@media print {
|
||||
.quiz-bar { display: none; }
|
||||
/* on paper the points are printed in the statement by quiz.lua, so the
|
||||
screen badge would say the same thing twice */
|
||||
.quiz-q-score { display: none; }
|
||||
.quiz-opt.quiz-ok, .quiz-opt.quiz-bad { background: none; }
|
||||
}
|
||||
@@ -0,0 +1,183 @@
|
||||
// quiz — judge the tick boxes of one quiz, score it in points, explain mistakes
|
||||
//
|
||||
// Every label the reader sees is written into the markup by quiz.lua, so the
|
||||
// wording follows the book's language and nothing is translated twice. A
|
||||
// quiz carries:
|
||||
// data-quiz-score "{n} of {m} questions correct"
|
||||
// data-quiz-points "{n} of {m} points" (the headline)
|
||||
// data-quiz-qpoints "{n}/{m} points" (one question's badge)
|
||||
// data-quiz-right verdict of a question answered correctly
|
||||
// data-quiz-wrong verdict of a question answered wrongly
|
||||
// and each question carries data-points / data-penalty.
|
||||
//
|
||||
// SCORING. A question is worth data-points (default 3). Every statement whose
|
||||
// box disagrees with its truth value — an unticked true one, or a ticked false
|
||||
// one — costs data-penalty (default 1). The result floors at zero, so a
|
||||
// question can never drag the total down. The quiz total is the sum over its
|
||||
// questions. A question still counts as "correct" for the verdict line only
|
||||
// when every one of its statements is right, which is the exam's
|
||||
// multiple-true-false rule.
|
||||
(function () {
|
||||
"use strict";
|
||||
|
||||
function options(quiz) {
|
||||
return quiz.querySelectorAll(".quiz-opt");
|
||||
}
|
||||
|
||||
// Number(undefined) || 3 would also swallow a deliberate 0, so test first.
|
||||
function num(el, name, dflt) {
|
||||
var raw = el.dataset ? el.dataset[name] : null;
|
||||
if (raw === undefined || raw === null || raw === "") return dflt;
|
||||
var n = Number(raw);
|
||||
return isFinite(n) ? n : dflt;
|
||||
}
|
||||
|
||||
// Substitute {n} and {m} into a template from metadata, building text nodes
|
||||
// rather than markup: the template is author text, never trusted as HTML.
|
||||
function render(el, template, n, m) {
|
||||
el.innerHTML = "";
|
||||
var parts = template.split(/\{n\}|\{m\}/);
|
||||
var values = (template.match(/\{n\}|\{m\}/g) || []).map(function (token) {
|
||||
return token === "{n}" ? n : m;
|
||||
});
|
||||
parts.forEach(function (text, i) {
|
||||
el.appendChild(document.createTextNode(text));
|
||||
if (i < values.length) {
|
||||
var b = document.createElement("b");
|
||||
b.textContent = String(values[i]);
|
||||
el.appendChild(b);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function judge(quiz) {
|
||||
var questions = quiz.querySelectorAll(".quiz-q");
|
||||
var right = 0, scored = 0, available = 0;
|
||||
|
||||
questions.forEach(function (q) {
|
||||
var ok = true;
|
||||
var misses = 0;
|
||||
var pts = num(q, "points", 3);
|
||||
var pen = num(q, "penalty", 1);
|
||||
|
||||
q.querySelectorAll(".quiz-opt").forEach(function (opt) {
|
||||
var box = opt.querySelector(".quiz-box");
|
||||
if (!box) return;
|
||||
var want = opt.dataset.correct === "1";
|
||||
var hit = box.checked === want;
|
||||
|
||||
opt.classList.toggle("quiz-ok", hit);
|
||||
opt.classList.toggle("quiz-bad", !hit);
|
||||
|
||||
// the explanation of an option is for the reader who got it wrong.
|
||||
// :scope > keeps this to the option's own .why — a question-level
|
||||
// .quiz-why-q also carries the class quiz-why.
|
||||
var why = opt.querySelector(":scope > .quiz-why");
|
||||
if (why) why.hidden = hit;
|
||||
|
||||
if (!hit) { ok = false; misses++; }
|
||||
});
|
||||
|
||||
var got = Math.max(0, pts - misses * pen);
|
||||
scored += got;
|
||||
available += pts;
|
||||
|
||||
var badge = q.querySelector(".quiz-q-score");
|
||||
if (badge) {
|
||||
badge.hidden = false;
|
||||
render(badge, quiz.dataset.quizQpoints || "{n}/{m}", got, pts);
|
||||
badge.classList.toggle("quiz-ok", misses === 0);
|
||||
badge.classList.toggle("quiz-bad", got === 0 && pts > 0);
|
||||
}
|
||||
|
||||
var verdict = q.querySelector(".quiz-verdict");
|
||||
if (verdict) {
|
||||
verdict.hidden = false;
|
||||
verdict.textContent = ok
|
||||
? (quiz.dataset.quizRight || "Correct")
|
||||
: (quiz.dataset.quizWrong || "Not quite");
|
||||
verdict.classList.toggle("quiz-ok", ok);
|
||||
verdict.classList.toggle("quiz-bad", !ok);
|
||||
}
|
||||
|
||||
// a question-level explanation backs up a wrong answer as a whole
|
||||
var qwhy = q.querySelector(".quiz-why-q");
|
||||
if (qwhy) qwhy.hidden = ok;
|
||||
|
||||
if (ok) right++;
|
||||
});
|
||||
|
||||
var score = quiz.querySelector(".quiz-score");
|
||||
if (score) {
|
||||
score.hidden = false;
|
||||
render(score, quiz.dataset.quizPoints || "{n}/{m}", scored, available);
|
||||
}
|
||||
}
|
||||
|
||||
function reset(quiz) {
|
||||
options(quiz).forEach(function (opt) {
|
||||
var box = opt.querySelector(".quiz-box");
|
||||
if (box) box.checked = false;
|
||||
opt.classList.remove("quiz-ok", "quiz-bad");
|
||||
var why = opt.querySelector(":scope > .quiz-why");
|
||||
if (why) why.hidden = true;
|
||||
});
|
||||
quiz.querySelectorAll(".quiz-verdict").forEach(function (v) {
|
||||
v.hidden = true;
|
||||
v.textContent = "";
|
||||
v.classList.remove("quiz-ok", "quiz-bad");
|
||||
});
|
||||
quiz.querySelectorAll(".quiz-q-score").forEach(function (b) {
|
||||
b.hidden = true;
|
||||
b.textContent = "";
|
||||
b.classList.remove("quiz-ok", "quiz-bad");
|
||||
});
|
||||
quiz.querySelectorAll(".quiz-why-q").forEach(function (w) { w.hidden = true; });
|
||||
var score = quiz.querySelector(".quiz-score");
|
||||
if (score) { score.textContent = ""; score.hidden = false; }
|
||||
}
|
||||
|
||||
document.addEventListener("click", function (event) {
|
||||
var target = event.target;
|
||||
if (!target.closest) return;
|
||||
|
||||
var check = target.closest(".quiz .quiz-check");
|
||||
if (check) {
|
||||
judge(check.closest(".quiz"));
|
||||
return;
|
||||
}
|
||||
var again = target.closest(".quiz .quiz-reset");
|
||||
if (again) {
|
||||
reset(again.closest(".quiz"));
|
||||
}
|
||||
});
|
||||
|
||||
// Re-ticking a box after checking clears that row's verdict, so a stale
|
||||
// green or red never sits next to a box the reader has just changed — and
|
||||
// with it the question's badge and the headline, which would otherwise
|
||||
// still claim a score for an answer that has since moved.
|
||||
document.addEventListener("change", function (event) {
|
||||
var box = event.target;
|
||||
if (!box.closest || !box.classList || !box.classList.contains("quiz-box")) return;
|
||||
var opt = box.closest(".quiz-opt");
|
||||
if (!opt) return;
|
||||
opt.classList.remove("quiz-ok", "quiz-bad");
|
||||
var why = opt.querySelector(":scope > .quiz-why");
|
||||
if (why) why.hidden = true;
|
||||
|
||||
var q = opt.closest(".quiz-q");
|
||||
if (q) {
|
||||
var badge = q.querySelector(".quiz-q-score");
|
||||
if (badge) { badge.hidden = true; badge.textContent = ""; }
|
||||
var verdict = q.querySelector(".quiz-verdict");
|
||||
if (verdict) { verdict.hidden = true; verdict.textContent = ""; }
|
||||
var qwhy = q.querySelector(".quiz-why-q");
|
||||
if (qwhy) qwhy.hidden = true;
|
||||
}
|
||||
var quiz = opt.closest(".quiz");
|
||||
if (quiz) {
|
||||
var score = quiz.querySelector(".quiz-score");
|
||||
if (score) score.textContent = "";
|
||||
}
|
||||
});
|
||||
})();
|
||||
Reference in new issue
Block a user