‹ back to the board

Friday, September 18

Novicesyntax & basics

The Chalkboard at the Sign of the Brass Tankard

The innkeeper chalks one line on the slate for every order that leaves the kitchen, and she wants them all written the same way.

An order is three things: name, the string written on the barrel or the tray; count, a non-negative integer number of items; and price, a non-negative integer number of coins each item costs.

Write chalkLine(name, count, price), which returns a single string of the form:

"<count> x <name> = <total> coins"

where <total> is count multiplied by price, and the parts are separated by single spaces exactly as shown. The final word is coins, except when the total is exactly 1, in which case it is coin.

Return the string; print nothing.

  • 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 "Turnip", count of 0, price of 7"0 x Turnip = 0 coins"
reward
120 XP
signature
chalkLine
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 at four coins
  • a single coin is singular
  • one item but nine coins stays plural
  • nothing ordered
  • free of charge
  • a long name with spaces
The Chalkboard at the Sign of the Brass Tankard · bitwick