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
- Your code has no type errors
- The order totals 115
- It uses
??for the default - It doesn't use the
!assertion - 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.
Press Run to see the page.
Console
Nothing printed yet.