Calling methods

Report a typo

SpongeBob has been learning about Go methods! He decided to create the DisplayQuotes() method that displays all of his famous phrases within the slice of strings Quotes.

When he tried to execute his program, he got a compilation error because he didn't use the proper syntax to call the DisplayQuotes() method correctly within the main function. Can you help SpongeBob by selecting all the proper ways to call the DisplayQuotes() method in his Go program?

Below is the code he has written:

package main

import "fmt"

type Quotes []string

// 'DisplayQuotes()' method will print all the quotes within the 'Quotes' slice
func (q Quotes) DisplayQuotes() {
    for _, quote := range q {
        fmt.Println(quote)
    }
}

func main() {
    spQuotes := Quotes{
        "I'm ready! I'm ready! 🧽",
        "I'm ugly and I'm proud! 👺",
        "Ravioli, ravioli, give me the formuoli! 🍝",
        "Krusty Krab pizza, it's the pizza for you and me! 🍕",
        "I heard in times of hardship, the pioneers would eat coral. 🪨",
    }

    ? // the selected option to call the 'DisplayQuotes()' method goes here! 
}

In this task, we implement a data type called slice within the Quotes variable; it holds all of the famous phrases SpongeBob is known for. You might've not learned about slices in Go yet, but do not worry! For this task, you don't necessarily need to know how slices work; the only objective is to select all the correct ways to call the DisplayQuotes() method within the main function.

Select one or more options from the list
___

Create a free account to access the full topic