functions2.goΒΆ

// functions2.go

package main

import (
    "fmt"
    "math"
)

func questions(name string) (string, string, string) {
    ask := func(prompt string) string {
        ans := ""
        fmt.Print(name + ", " + prompt + " ")
        fmt.Scanf("%s", &ans)
        return ans
    } // ask

    color := ask("what's your favourite color?")
    shape := ask("what's your favourite shape?")
    pet := ask("what's the name of your first pet?")
    return color, shape, pet
}

func main() {
    c, s, p := questions("Dave")
    fmt.Println(c, s, p)
    // or you could do the same thing in one line:
    // fmt.Println(questions("Dave"))
}