The Chalkboard at the Sign of the Brass Tankard
The innkeeper chalks one line on the slate for every order that leaves the kitchen, and she wants them all written the same way.
An order is three things: name, the string written on the barrel or the tray; count, a non-negative integer number of items; and price, a non-negative integer number of coins each item costs.
Write chalkLine(name, count, price), which returns a single string of the form:
"<count> x <name> = <total> coins"
where <total> is count multiplied by price, and the parts are separated by single spaces exactly as shown. The final word is coins, except when the total is exactly 1, in which case it is coin.
Return the string; print nothing.
examples
- case 1
name of "Barley Ale", count of 3, price of 4"3 x Barley Ale = 12 coins" - case 2
name of "Millet Loaf", count of 1, price of 1"1 x Millet Loaf = 1 coin" - case 3
name of "Turnip", count of 0, price of 7"0 x Turnip = 0 coins"
- reward
- 120 XP
- signature
chalkLine
TypeScript, run as ES2022 — types are stripped, not checked. If a JS engine would run it, so will we.
- three ales at four coins
- a single coin is singular
- one item but nine coins stays plural
- nothing ordered
- free of charge
- a long name with spaces