Chapter 21 of 22 Part V: Artificial Intelligence and Intelligent Devices

NFC: The Secret Power of a Tap

3 Verified Book Snippets

Every .js file below is byte-identical (SHA-256 verified) to the printed code in Volume 1. Runnable blocks execute inside an isolated sandboxed iframe and Web Worker with a 2-second timeout and zero network access.

Download Chapter ZIP

Coupling (Ch. 21 Example 1)

File: block-01.js (byte-identical) · 184 bytes · SHA-256: 04993973e806…
NFC Standalone runnable

Dependencies: None (standard ES2022 JavaScript). Runs directly in Node.js or the isolated Web Worker sandbox and prints console output.

function coupling(d, alignment) {
  if (d < 0 || alignment < 0 || alignment > 1)
    throw Error("Invalid model input");
  return alignment / (1 + d * d);
}
console.log(coupling(2,1));
Download .js

Fits Text (Ch. 21 Example 2)

File: block-02.js (byte-identical) · 165 bytes · SHA-256: 567dd8387ef3…
NFC Standalone runnable

Dependencies: None (standard ES2022 JavaScript). Runs directly in Node.js or the isolated Web Worker sandbox and prints console output.

function fitsText(text, budget) {
  const bytes = new TextEncoder().encode(text).length;
  return {bytes, fits: bytes <= budget};
}
console.log(fitsText("Hello",8));
Download .js

Classify Tap (Ch. 21 Example 3)

File: block-03.js (byte-identical) · 339 bytes · SHA-256: dbfde6aa0465…
NFC Standalone runnable

Dependencies: None (standard ES2022 JavaScript). Runs directly in Node.js or the isolated Web Worker sandbox and prints console output.

function classifyTap(value) {
  try {
    const u = new URL(value);
    return u.protocol === "https:" &&
      u.hostname === "museum.example" &&
      !u.username && !u.password && !u.port
      ? "Review known host" : "Do not open";
  } catch { return "Not a web address"; }
}
console.log(classifyTap("https://museum.example/exhibit"));
Download .js