‹ back to the board

Friday, September 11

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 count is 0, return the name, then a colon, then a space, then out of stock — for example a name of Cider gives Cider: out of stock.
  • Otherwise the total is count multiplied by price, and the line is the count, a space, a lowercase x, a space, the name, a space, =, a space, the total, a space, and then the coin word.
  • The coin word is coin when the total is exactly 1, and coins for every other total.

No trailing spaces, no punctuation beyond what is described.

  • string formatting
  • Novice

examples

  1. case 1name of "Barley Ale", count of 3, price of 4"3 x Barley Ale = 12 coins"
  2. case 2name of "Millet Loaf", count of 1, price of 1"1 x Millet Loaf = 1 coin"
  3. case 3name of "Pickled Eel", count of 0, price of 7"Pickled Eel: out of stock"
  4. case 4name 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
not yet run

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
The Slate Board of the Salted Hart · bitwick