‹ back to the board

Friday, September 25

Novicesyntax & basics

The Chalkboard of the Hearth and Hammer

The innkeeper of the Hearth and Hammer chalks one line on the board for every order that leaves the kitchen, and the lines must all be the same width so the board reads clean from the door.

Write tallyLine(name, count, price).

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

Return a single string built like this:

1. The tally is the count, a space, the letter x, a space, then the name: e.g. 3 x Barley Ale. 2. The total is count multiplied by price. The charge is that total, a space, then the word coin if the total is exactly 1, and coins otherwise. 3. The returned line is the tally, then a run of . dots, then the charge, with the dots chosen so the whole line is exactly 32 characters long. 4. If the tally and the charge together take up 31 characters or more, there is no room for a proper run: put exactly one dot between them, and the line is longer than 32 characters.

The return value is that string. No leading or trailing spaces are added anywhere.

  • string formatting
  • Novice

examples

  1. case 1name of "Barley Ale", count of 3, price of 4"3 x Barley Ale..........12 coins" - the tally is 14 characters, the charge "12 coins" is 8, so 10 dots fill the gap to 32
  2. case 2name of "Mead", count of 1, price of 1"1 x Mead..................1 coin" - the total is 1, so the charge is singular, and 18 dots fill the gap
  3. case 3name of "Thrice-Distilled Dragonfire Brandy", count of 2, price of 50"2 x Thrice-Distilled Dragonfire Brandy.100 coins" - tally and charge already overflow the board, so exactly one dot separates them
reward
120 XP
signature
tallyLine
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 fill the board
  • a single coin is singular
  • nothing ordered still costs coins plural
  • a long name overflows to one dot
  • exactly one dot still reaches 32
  • one character over the board
The Chalkboard of the Hearth and Hammer · bitwick