×

go · level 1 · unit 7 · lesson 2

  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

A is a slot where your function catches information.

Picture your function as a machine. Right now it does the same thing every time. Cut a slot in the front, and you can feed in something new on each go.

That slot is a parameter. It sits in the brackets of the func line, with its type after it: func greet(name string). Inside the function, use it like any other box.

The value you drop in when you call is the . greet("Mia") puts "Mia" into name. Hand over the wrong type, like greet(7), and Go refuses to run.

package main
import "fmt"
func greet(name string) {
	fmt.Printf("Hello, %v!\n", name)
}
func main() {
	greet("Mia")
	greet("Leo")
}

For two slots, separate them with a comma: func order(food string, drink string).