Regular Customers

The blacksmith has regular customers, and some of them get a discount: a number of gold coins off every order. They're in the new array regulars, whose elements have the type Customer. Not every regular has a discount, so discount is an optional property.

A regular with a discount pays the price minus the discount, and the line of the order ends with the discount in parentheses. A regular without a discount pays the full price. A customer who isn't among the regulars pays the full price too, but the line ends with (new customer). The total is now what the customers really pay:

Kira: forging, Arrowheads (steel), 30 gold (5 off)
Bruno: repair, Battle Axe, 15 gold (new customer)
Lena: sharpening, Dagger, 8 gold
Bruno: forging, Shield (bronze), 20 gold (new customer)
Total: 73 gold

Kira's discount is 5 gold, so she pays 30 for her arrowheads. Lena is a regular without a discount, and Bruno isn't a regular at all.

A tip: when you look for a customer with find, remember from the Unions and Narrowing lesson that it may find nothing. TypeScript makes you handle that case, and the missing discount too.

Instructions

Change the lines of the orders: show the discounts, and mark the customers who aren't regulars.

Print the total that the customers pay.

Start programming for free

By signing up, you agree to the Terms of Service and Privacy Policy.

Or sign up with:

2/3