Your map now answers two of Grace’s questions: where the confirmation comes from and which formatPrice() each output uses. Both questions ask where a line lives. Her first question in docs/FIRST-HOUR.md is “How does READ20 get applied?” It asks what the code works out, and that calls for a different kind of reading.
In this lesson, you’ll choose how closely to read for a question, record assumptions about the functions you haven’t opened, and check what you read with a run. Start by deciding how closely you need to read to answer Grace’s question.
Match the Reading to the Question
Reading every line of every file you open costs time, and most questions don’t need it. Match the reading to what the question asks for. There are three kinds of reading, and you’ve already used two:
- To skim is to read only a file’s names, imports, exports, and comments to learn its shape. It answers “What’s in here, and where does it lead?”
- To trace is to follow one call from file to file, reading only the line that leads on. You traced in the last lesson, from line 27 of
createOrder()toorderMessage()insrc/email/templates.js. It answers “How does this get from here to there?” - To read closely is to go line by line and keep track of every value. It answers “What exactly does this work out?”
Grace’s question asks how a discount code changes a price, so it needs a close read, but only of the function that does the pricing. Her notes point to priceOrder() in src/orders/pricing.js. Skim that file first, reading only the import lines, the function names, and the comments.
The skim shows imports of findDiscount() and discountAmount() from src/discounts/codes.js and requirePence() from src/lib/money.js, and one function, priceOrder(state, lines, code). That’s the one to read closely.
If you have your own question about the shop, this button asks Code Mentor which kind of reading fits it. Add your question before you send: