All challenges

TypeScript · easy

Cart that lies

#18

Situation

Checkout bills one unit per line, even when the order says six. A customer bought 6 licenses and the invoice charged for 1, so cartTotal is ignoring qty.

Objective

Calculate each line from its price and quantity, then add the lines together. For (100¢×2) and (50¢×3), return 350; an empty cart returns 0.

The repo at start

workspace/
└── src/
    └── cart.ts   (qty is decorative)

Checks you will turn green

  • exports cartTotal
  • two lines with qty total 350
  • empty cart is 0

Concepts

arraysreduce

Play it in your terminal

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

sharpen 18

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 18
  4. or Or try it without installing anything:
    npx @juanwmedia/sharpen 18
  5. 4 And to update when a new version ships:
    sharpen update