‹ back to the board

Saturday, September 12

Novicesyntax & basics

The Tap-Room Slate

The innkeeper of the Wet Badger chalks one line on the slate for every order that leaves the kitchen, and last night's cellar-hand chalked them all crooked. She wants a carver who can write the lines the same way every time.

Write slateLine(name, count, price).

  • name is a string: the item ordered.
  • count is a non-negative integer: how many were ordered.
  • price is a non-negative integer: the cost in coins of a single one.

Return a single string of the form:

NAME xCOUNT = TOTAL coins

where NAME is name exactly as given, COUNT is count, and TOTAL is count multiplied by price. The spaces and the x and the = appear exactly as shown above.

The last word is coins, except when the total is exactly 1, in which case it is coin.

  • string formatting
  • Novice

examples

  1. case 1name of "Barley Ale", count of 3, price of 4"Barley Ale x3 = 12 coins"
  2. case 2name of "Tallow Candle", count of 1, price of 1"Tallow Candle x1 = 1 coin" (the total is 1, so the word is singular)
  3. case 3name of "Turnip", count of 0, price of 7"Turnip x0 = 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
  • total of one is singular
  • nothing ordered
  • free kindling stays plural
  • one costly item
  • a long order
The Tap-Room Slate · bitwick