Locked learning resources

Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Locked learning resources

This lesson is for members only. Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Ask Code Mentor and Check It

In this video, you asked Code Mentor one specific question about findDiscount(), split its reply into claims, and marked each claim confirmed, wrong or unchecked from a line of code and a run on the staff desk.

Key Points

  • Code Mentor can be a second reader. Treat its answer like a colleague’s notes. They’re useful, but you check them before you pass them on.
  • Asking it to explain the whole codebase gets you an overview that sounds right but gives you nothing to check.
  • A useful question asks about one behavior, gives the code it’s about, and asks for the line behind each claim. The button below brings the code along. For your own questions, paste the function’s code under the question.
  • The reply in the video is an example, written for it. Yours will differ, and it may get different claims right or wrong. Split any reply into claims: single statements about what the code does, each true or false on its own.
  • Give each claim one of three marks:
    • Confirmed: The line says it, and a run shows it.
    • Wrong: The line or a run contradicts it.
    • Unchecked: You don’t have both yet. Write down what’s missing.
  • Unchecked isn’t wrong. It stays an assumption until a question of yours depends on it.
  • When a claim is wrong, tell Code Mentor which line contradicts it, and check its next answer the same way.

Ask One Specific Question

The question in the video was about findDiscount() in src/discounts/codes.js. The button after the code opens Code Mentor with the same question typed in and this code included. Send it, and keep the reply open. Here’s the code, with the long line 5 broken in two to fit:

Locked learning resources

Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Already a member? Sign-In

Locked learning resources

The full lesson is for members only. Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Already a member? Sign-In

00:00 Your map has findDiscount() checked for two codes: READ20 is applied, and OLD120 is refused. The last exercise added a third: read20 in lower case is accepted.

00:12 Grace’s question at the end of the course is about a code that didn’t work. Your map doesn’t hold every case yet, such as an empty code, or where the codes come from.

00:22 Code Mentor can be a second reader. Treat its answer like a colleague’s notes. They’re useful, and they get checked before you pass them on. Watch out for the broad question.

00:34 Asking it to explain this codebase gets you an overview that sounds right but gives you nothing to check. So ask about one behavior: what findDiscount() does with a typed code.

00:47 Give it the code, so it answers from these lines. The button below this video brings the code along. For your own question, paste the function under it. Then ask for the line behind each claim.

00:59 Here’s an example reply to check together. Yours will differ, and it may get different claims right or wrong.

01:07 A paragraph is too much to check at once, so check it one claim at a time. A claim is one statement about what the code does, true or false on its own. This reply holds four.

01:21 An empty code means full price. The match is case sensitive, so read20 in lower case is refused. A code with no active match throws an error. And the shop reads its codes from a data file for every order.

01:35 Each claim gets one of three marks. Confirmed means the line says it and a run shows it. Wrong means the line or a run contradicts it. Unchecked means you don’t have both a line and a run yet.

01:51 Claim one points to line 2. If the code is empty, it returns a record with zero percent off. Now run it. On the staff desk, place one Small Maps for Nadia Patel with the code left empty.

02:04 The new row shows £7.50 paid, the full price. Confirmed.

02:10 Claim two points to line 5. It compares each record’s code with the typed code after toUpperCase(), which turns it into capitals. You ran this case in the last exercise: read20 in lower case came to 600 pence, the READ20 price.

02:27 On the staff desk, it’s £6.00 too. The line and the run both contradict the claim, so it’s wrong.

02:36 Claim three points to line 7, which runs when no record both matches and is active. OLD120 is switched off, so place the order with it. The message under the form is that same error.

02:48 Confirmed.

02:50 Claim four names no line. Reading files is the storage code’s job, and you haven’t opened it. No run so far shows when the file is read. So it’s unchecked, with what’s missing written down: a line and a run.

03:05 Unchecked isn’t wrong. It stays an assumption until a question of yours depends on it. When a claim is wrong, tell Code Mentor which line contradicts it, and check its next answer the same way.

03:18 So ask one specific question, with the code given and a line for each claim. Then mark each claim from a line and a run, never from how sure the reply sounds.

03:30 Add the marked claims to your map, under your READ20 entry. Next comes Exercise: Check an Explanation Claim by Claim, where you’ll check a reply about the welcome code Grace wants to print on cards.

Become a Member to join the conversation.