Skip to content

C1 Receipt trace

8 minSuggested first: L06 Types and failure paths

Outcome

Trace a loop, a branch and a return by hand, without running the code.

The case

Three short items about one function. Each has one accepted answer and can be retried. After a miss, the review link names the lesson to revisit. Three out of three is a sign you're ready for the next group, not a gate: nothing is locked.

JavaScript
function receipt(prices) {
  let total = 0;
  for (const price of prices) {
    if (price > 0) total += price;
  }
  return total >= 10 ? total - 2 : total;
}
const due = receipt([4, 0, 6]);

Checkpoint items

1. Branch

Counts toward completion

When the loop reaches the price of 0, what happens to total?

Choose one answer

2. State

Counts toward completion

Which list gives total after each iteration, in order?

Choose one answer

3. Return

Counts toward completion

What value does due receive?

Choose one answer

Review

After each group, do its checkpoint in one sitting and revisit one missed item the next day. Then try a puzzle in a repository you haven't read yet.