All challenges

TypeScript · easy

Make the doc

#24

Situation

Billing uses one document builder for invoices and credits, but every call currently produces an invoice. A credit note therefore charges the customer again instead of returning the money.

Objective

Build the document that matches the requested kind: invoices keep a positive total and credits make it negative. makeDoc("invoice", 10){ type: "invoice", total: 10 }; makeDoc("credit", 10){ type: "credit", total: -10 }.

The repo at start

workspace/
└── src/
    └── docs.ts   (always builds an invoice)

Checks you will turn green

  • exports makeDoc
  • invoice keeps positive total
  • credit negates total

Concepts

unionsfunctions

Play it in your terminal

With sharpen installed, this command opens exactly this challenge in your local arena:

sharpen 24

First time? The full install is right below.

How to play

  1. 1 Install Claude Code if you do not have it yet: claude.com/claude-code
  2. 2 Install sharpen from npm:
    npm install -g @juanwmedia/sharpen
  3. 3 Then launch it; the arena opens in your browser:
    sharpen 24
  4. or Or try it without installing anything:
    npx @juanwmedia/sharpen 24
  5. 4 And to update when a new version ships:
    sharpen update