Homework
Homework — text in your app
YOUR app: a clean display and a correct text check.
Requirements:
- Update
formatItemwithfmt.Sprintfand alignment (%-Ns) so your record looks tidy (title, number, status). Adapt it to your theme (movie, expense, workout…). - Add a text-field check by character count (
utf8.RuneCountInStringor[]rune): the title/name can't be empty and no longer than a limit you pick. Bad input — a message andcontinue. - Read multi-word text with
readLine, notfmt.Scanln— so a title with spaces is read in full. - Prove the gotcha. Add a Lithuanian title (e.g. "Ąžuolų giraitė") and show that
len(title)andutf8.RuneCountInString(title)return different numbers. The check must use characters. gofmt+ a workinggo run.
Extra (for those who want more): add a tags field — the user types "adventure, classic, 2020", and you turn it into a []string with strings.Split + TrimSpace. Show it back with strings.Join.
To submit: the code + a transcript showing: (1) a Lithuanian title read in full, (2) the len vs utf8.RuneCountInString difference for that title, (3) a too-long title being rejected.
Tip. Your app still holds one record. Next lesson is the second milestone:
[]Item, and your menu learns to hold a whole list — adding and listing many records. And thenstrings.Builderfrom step 2 pays off: joining the whole list into one tidy report.