Command Palette

Search for a command to run...

Hectal
Phase 1: Basic Types and Annotations
TypeScript · Exercise 6 of 6 Previous
Beginner

Total an Order With Optional Discounts

Each item has a price and an optional discount. total subtracts the discount, but the optional property may be missing and TypeScript reports it.

Fix total without using the ! operator. Items without a discount must count as a discount of 0.

What Check tests

  1. Your code has no type errors
  2. The order totals 115
  3. It uses ?? for the default
  4. It doesn't use the ! assertion
  5. An item without a price is rejected

Stuck? One hint at a time

The solution unlocks after your first Check. Try first: that is where the learning happens.

Runs in your browser. Your code is saved here.

Console

Nothing printed yet.