Completed
Available
Locked · open anytime

Level 1: Beginner Go Exercises

Level 1 teaches Go through the small jobs a backend developer meets every day: format a price, count status codes in a log, clean up tags typed by users, read a port from config, sort products and parse a URL query string.

Every lesson names one trap that compiles fine but gives wrong results, like append overwriting the caller's slice, writing to a nil map, slicing a string by bytes or an empty case that silently does nothing. Your code runs in a real Go interpreter inside your browser, and the tests are chosen so that only an answer that avoids the trap passes.

The 10 exercises in this level

  1. 1 Formatting Prices Cents to euros, without floats Format an amount stored in cents as a price like €12.05 in Go, with integer division, the % operator and %02d, and no float rounding errors. Start here — no prerequisites
  2. 2 Slices and append Remove a cart item without touching the original Remove an item from a shopping cart slice in Go without overwriting the caller's slice: slices share their array, so build a new one instead. Start here — no prerequisites
  3. 3 Maps Count HTTP status codes in a log Count how often each HTTP status code appears in a Go server log with a map, and avoid the panic of writing to a nil map. Recommended first: Slices and append
  4. 4 Strings and Runes Shorten a title without breaking a letter Shorten titles for cards and notifications in Go without cutting a letter in half: count runes instead of bytes, and slice a []rune, not the string. Recommended first: Formatting Prices
  5. 5 Splitting Strings Clean up tags typed by users Turn a comma-separated list of tags typed by users into clean, lowercase tags in Go with strings.Split, TrimSpace and ToLower, skipping empty pieces. Recommended first: Strings and Runes
  6. 6 Errors as Values Read a port number from config Read a port number from a config value in Go with strconv.Atoi, returning an error for text or out-of-range numbers instead of silently using 0. Recommended first: Formatting Prices
  7. 7 Range and Structs Apply a discount to every item Apply a percentage discount to every item of a Go slice of structs in place, and learn why changing the range variable changes only a copy. Recommended first: Slices and append
  8. 8 Switch Which HTTP errors are worth a retry Decide which HTTP status codes an API client should retry with a Go switch, and avoid the empty case that silently does nothing because Go never falls through. Recommended first: Errors as Values
  9. 9 Sorting with sort.Slice Cheapest first, ties by name Sort a product list in Go with sort.Slice, cheapest first and equal prices by name, because sort.Slice is not stable and won't keep ties in order for you. Recommended first: Range and Structs
  10. 10 Project: Query String Parser Turn ?page=2&tag=go into a map Build a URL query string parser in Go: split on &, cut each pair at the first =, and collect repeated keys into a map of slices, the way net/url's ParseQuery does (without URL decoding). Recommended first: Maps, Splitting Strings

Frequently asked questions

Do I need to install Go?
No. A Go interpreter runs in your browser, so there is nothing to install. When you are ready for your own projects, install Go from go.dev and the same code works there.
Why is len("é") 2 in Go?
A Go string holds bytes encoded in UTF-8, and "é" takes two bytes. `len` counts bytes. To count letters, convert to `[]rune` or loop with `range`, which steps one rune at a time.
Why does Go return errors instead of throwing exceptions?
An error is an ordinary value returned next to the result, so every call site decides what to do with it. The "Errors as Values" exercise shows why `n, _ := strconv.Atoi(s)` is a bug waiting to happen.