×

go · level 1 · unit 3 · 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

fills in the gaps in a sentence.

fmt.Printf fills in a sentence for you. Write the text with %v wherever a value should go, then list the values after commas. Each %v is a , and they are filled in order.

Printf does not move to a new line on its own, so end the text with \n, which means new line. works the same way but hands the text back, ready to store in a box.

To join a number onto a string with +, turn it into text first. The toolbox does that: strconv.Itoa(10) hands back "10".

package main
import "fmt"
import "strconv"
func main() {
	name := "Ava"
	score := 42
	fmt.Printf("%v scored %v points\n", name, score)
	label := fmt.Sprintf("Player: %v", name)
	fmt.Println(label)
	fmt.Println("Score: " + strconv.Itoa(score))
}

Itoa is short for "integer to ASCII", an old way of saying number to text.