JavaScript · Module 8
Answers and explanations · Organize modules and debug with evidence
Compare these references after your own attempt. You can read them at any time; they do not record a live model or vendor run.
JavaScript · Module 8
Compare these references after your own attempt. You can read them at any time; they do not record a live model or vendor run.
A: if a required module cannot be fetched, the dependent entry module cannot finish loading and its top-level body does not execute. Inspect Network for the missing path and the Console for the import failure. A browser security error from file:// is a different setup problem.
B: “0 places available” is a valid string, so parsing succeeds. The requirement says zero should display Full, and the assertion exposes the mismatch. Repair the rule rather than editing the test to accept an unintended answer.
C: capacity.js:
export function canFit(available, requested) {
return Number.isInteger(requested)
&& requested >= 1 && requested <= available;
}
app.js:
import { canFit } from "./capacity.js";
console.assert(canFit(4, 0) === false, "Zero request");
console.assert(canFit(4, 1.5) === false, "Fractional request");
console.assert(canFit(2, 3) === false, "Over capacity");
A breakpoint lets you inspect available and requested inside their scope. Remove temporary debugging pauses before handing over the code.