Novicesyntax & basics
The Slate Above the Hearth
The innkeeper at the Kettle & Crow chalks every sale onto the slate above the hearth, and her hand is tired. She wants each line written the same way, every time.
Write slateLine(name, count, price).
nameis a string: the name of the good, written exactly as it should appear.countis a non-negative integer: how many were sold.priceis a non-negative integer: the cost in coins of a single one.
Let the total be count multiplied by price. Return a single string of the form:
"<count> x <name> = <total> coins"
with single spaces exactly where shown, a lowercase x between the count and the name, and no leading or trailing spaces. The last word is coin when the total is exactly 1, and coins for every other total.
examples
- case 1
name of "Barley Ale", count of 3, price of 4"3 x Barley Ale = 12 coins" - case 2
name of "Tallow Candle", count of 1, price of 1"1 x Tallow Candle = 1 coin" - case 3
name of "Salt Cod", count of 1, price of 9"1 x Salt Cod = 9 coins" - case 4
name of "Turnip", count of 0, price of 7"0 x Turnip = 0 coins"
- reward
- 120 XP
- signature
slateLine
TypeScript, run as ES2022 — types are stripped, not checked. If a JS engine would run it, so will we.
loading the editor…
- three ales
- a single coin is singular
- one item, many coins
- none sold
- free goods
- empty name still formats