Lab: Core syntax review
Consolidate your Go core syntax knowledge with quizzes covering all six lessons and coding challenges to try in your local editor.
- Recall key rules for variables, functions, control flow, collections, and structs
- Predict Go compiler behaviour from short code snippets
- Identify idiomatic Go patterns versus common mistakes
This is an optional lab. No new concepts — just a chance to consolidate what you've learned across the core syntax module. Work through the quiz sections, then try the coding challenges in your own editor.
Go's design philosophy is that the language should be easy to read, even by someone who didn't write it. This lab asks you to read short programs and predict what they do — or whether they compile at all. That habit of reading before running is one of the most efficient ways to internalise a language.
Section 1 — Variables and types
Knowledge check
- 1.What is the zero value of a bool in Go?
- 2.Does this code compile?
package main var x := 10 func main() {} - 3.In Go, you can reassign a const after it has been declared.
Section 2 — Functions
Knowledge check
- 1.A function signature is
func open(path string) (*File, error). Which line correctly calls it and handles the error? - 2.You have
nums := []int{1, 2, 3}andfunc sum(vals ...int) int. Which call passes the slice as individual arguments? - 3.In Go,
_can be used on the left side of := to intentionally discard a return value.
Section 3 — Control flow
Knowledge check
- 1.What does this print?
colors := []string{"red", "green", "blue"} for i, c := range colors { fmt.Println(i, c) } - 2.In a Go switch, what happens if no case matches and there is no default clause?
- 3.In
if err := doWork(); err != nil { ... }, what is the scope of err?
Section 4 — Arrays, slices, and maps
Knowledge check
- 1.What is wrong with this code?
s := []int{1, 2, 3} append(s, 4) fmt.Println(s) - 2.How do you check whether the key "x" exists in
m map[string]int? - 3.A sub-slice created with s[1:3] shares the underlying array with the original slice s.
Section 5 — Structs and methods
Knowledge check
- 1.When should you prefer a pointer receiver over a value receiver?
- 2.You define
type person struct { name string }in package models. Can another package read the name field? - 3.Go supports class-based inheritance through the class keyword.
Coding challenges
These won't run in the browser — Go needs a local compiler. Use the project from the first lesson (go run main.go to execute).
Challenge 1: FizzBuzz
Write a fizzBuzz(n int) string function that returns "Fizz" if n is divisible by 3, "Buzz" if divisible by 5, "FizzBuzz" if both, and the string form of n otherwise. Use it in a loop from 1 to 20 and print the results. Use fmt.Sprintf("%d", n) to convert an integer to string.
Hint: Check the combined case (n%3 == 0 && n%5 == 0) first, otherwise "Fizz" or "Buzz" will match before you reach "FizzBuzz".
Challenge 2: Word count
Write a function wordCount(words []string) map[string]int that returns a map of each word to how many times it appears. Test it on []string{"go", "is", "fast", "go", "is", "simple", "go"}. Then range over the map and print each word with its count.
Challenge 3: Temperature converter
Define a Temperature struct with a Celsius float64 field. Add:
Fahrenheit() float64— returns the Fahrenheit equivalent.String() string— returns a human-readable string like"100.00°C / 212.00°F"usingfmt.Sprintf.
Create a []Temperature slice with a few values and print each one.
Challenge 4: Stack (stretch)
Implement a stack using a struct wrapping a []int. Add methods Push(v int), Pop() (int, bool) (returns the top element and whether one was available), and Len() int. Use pointer receivers. Test by pushing several values and popping them — they should come out in reverse order.
When the agent's away
The best next step is writing small programs from scratch. Type every line — don't paste:
mkdir go-practice
cd go-practice
go mod init example.com/practice
# create main.go, write code, run it
go run main.go
go fmt ./...
go vet ./...The official Go Tour at tour.golang.org is free, interactive, and covers everything in this module plus more. For deeper reading, the Effective Go document explains the idioms that distinguish good Go from merely correct Go.
Where to go next
You've completed the core syntax module. The natural next step is the intermediate track, which covers Go's interface system, goroutines and channels for concurrency, error wrapping, and standard library patterns for I/O and testing.