Your 20-minute checkpoint
Close the earlier examples. Spend two minutes writing the inputs, expected outputs, and steps in plain language. Use about eight minutes to build and test, then five to explain your choices and try the variation. Taking longer is normal: these are study budgets, not speed tests.
Use records, arrays, and deliberate copying. This problem deliberately changes the setting so you practice choosing the tools yourself.
Acceptance cases before you code
Before you write code, decide what each case below should print. Then work through them by editing the array of records and pressing Run again. A quantity above one and an untouched original record catch different mistakes.
| Case to try | What your result should demonstrate |
|---|---|
| Empty packing list | Zero pieces and no unpacked names |
| Packed item with quantity greater than one | Count pieces, not just records |
| Revise the first record, then inspect the original | The revised packed flag changes without changing the source record |
When everything prints correctly, change the copy to const revised = items[0]; on purpose and see which case shows the mistake. Put it back, then say in one sentence which rule the mistake broke. If you cannot remember how to do a step, revisit that lesson before opening the solution.
An equipment inventory
Each item has name, quantity, and packed. Count all pieces and list unpacked names. Then make a revised copy of the first record marked packed, leaving the original unchanged.
const items = [
{ name: "Notebook", quantity: 2, packed: false },
{ name: "Pen", quantity: 3, packed: true }
];Hint 1: the idea
Use a number for the total and an array for the names.
Hint 2: a first step
Loop through items; add quantity and push name only when packed is false.
Show one solution
const items = [
{ name: "Notebook", quantity: 2, packed: false },
{ name: "Pen", quantity: 3, packed: true }
];
let pieces = 0;
const unpacked = [];
for (const item of items) {
pieces += item.quantity;
if (!item.packed) {
unpacked.push(item.name);
}
}
const revised = { ...items[0], packed: true };
console.log(pieces);
console.log(unpacked.join(", "));
console.log(items[0].packed);
console.log(revised.packed);5
Notebook
false
trueTry two unpacked items. Then test the counting and name-listing part with no items; it should count zero. Skip making a copy of the first item when the list is empty, because there is no first record. Decide what text an empty unpacked list should display instead of a blank line.
Change the requirements
Try two unpacked items. Then test the counting and name-listing part with no items; it should count zero. Skip making a copy of the first item when the list is empty, because there is no first record. Decide what text an empty unpacked list should display instead of a blank line.
Decide what to revisit
- Can you explain each variable and the reason for each condition?
- Did you check an empty, boundary, or changed input rather than only the supplied one?
- Can you rebuild the essential part after closing the solution?
If you needed a hint, record the specific missing idea and revisit that lesson. Marking a page done records progress; it does not replace practice. Begin tomorrow by rebuilding one small part from memory.
Completion is saved in this browser only. It does not measure mastery.