‹ back to the board

Saturday, September 5

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).

  • name is a string: the name of the good, written exactly as it should appear.
  • count is a non-negative integer: how many were sold.
  • price is 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.

  • 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 "Tallow Candle", count of 1, price of 1"1 x Tallow Candle = 1 coin"
  3. case 3name of "Salt Cod", count of 1, price of 9"1 x Salt Cod = 9 coins"
  4. case 4name of "Turnip", count of 0, price of 7"0 x Turnip = 0 coins"
reward
120 XP
signature
slateLine
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, many coins
  • none sold
  • free goods
  • empty name still formats
The Slate Above the Hearth · bitwick