Novicesyntax & basics
The Slate Board of the Salted Hart
The inn called the Salted Hart chalks one line on its slate board for every barrel and crate in the cellar, and the potboy keeps rubbing them out crooked. The cellar-keeper wants the lines written the same way every time.
Write shelfLabel(name, count, price), where name is a string (the goods), count is a non-negative integer (how many are in the cellar), and price is a non-negative integer (the cost in coins of one of them).
It returns a string, built by these rules:
- If
countis0, return the name, then a colon, then a space, thenout of stock— for example a name ofCidergivesCider: out of stock. - Otherwise the total is
countmultiplied byprice, and the line is the count, a space, a lowercasex, a space, the name, a space,=, a space, the total, a space, and then the coin word. - The coin word is
coinwhen the total is exactly1, andcoinsfor every other total.
No trailing spaces, no punctuation beyond what is described.
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 "Pickled Eel", count of 0, price of 7"Pickled Eel: out of stock" - case 4
name of "Turnip", count of 5, price of 0"5 x Turnip = 0 coins" — a total of zero is still plural
- reward
- 120 XP
- signature
shelfLabel
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, nine coins, still plural
- empty shelf
- free goods total zero
- nothing at no price