Start learning free

LESSON 39 OF 671 · FUNCTIONS I

Exercise: Create Function with Parameters in Go

Practice

We've written this code:

func mainFunction() {
    fmt.Println("My name is Andy")
    fmt.Println("I code in Python")
    fmt.Println("I have a dog")

    fmt.Println("My name is Mike")
    fmt.Println("I code in Java")
    fmt.Println("I have a cat")

    fmt.Println("My name is Sarah")
    fmt.Println("I code in JavaScript")
    fmt.Println("I have a parrot")
}

Write the same code in a better way by creating and calling a function with parameters named printMessages.

The function should accept name, language, and animal, then print the three matching lines.

Assignment
Define printMessages, then call it for Andy, Mike, and Sarah.


STEP 1 OF 5
    Ctrl + Enter to check