×

go · level 1 · unit 7 · lesson 4

  1. meet it
  2. guess first
  3. your turn
  4. fix it
  5. nailed it

Tap a green word if you get lost.

meet it

Big programs are small pieces working as a team.

A bundles values into one, like a pet's record card. type Pet struct lists its fields, each with a name and a type. Make a card with Pet{Name: "Rex", Age: 3}, and read a with a dot: pet.Name.

Real programs are built from small parts. A slice of structs holds the data, a loop walks through it, a function answers one question and an if decides what to do.

When something goes wrong, you : find the bug, fix it, run again. Every programmer does this every day. Small functions help, because you can test each one on its own.

package main
import "fmt"
type Pet struct {
	Name string
	Age  int
}
func main() {
	pets := []Pet{{Name: "Rex", Age: 3}, {Name: "Tibbles", Age: 12}}
	for _, pet := range pets {
		fmt.Printf("%v is %v\n", pet.Name, pet.Age)
	}
}

Inside a slice of Pet, you can leave out the word Pet before each card's curly brackets.