
// in your video it worked but when i try to do it on my editor idk why i get thie serror .
//main.go
package main
// import "fmt"
func main() {
cards := []string{ "Ace of Diamonds", newCard(), newCard()} // a slice of type string
cards = append(cards, "new element")
cards.print()
}
func newCard() string {
return "Five of Diamonds"
}
// deck.go
package main
import "fmt"
// Create a new type of 'deck'
// which is a slice of strings
type deck []string
// fun that belongs to deck type , we shoudl print the each card on println
func (d deck) print() {
for i, card := range d {
fmt.Println(i, card)
}
}
//
Hi
Same issue with me, I just started the Udemy course;
on MacOS Mojave 10.14.3 (18D109);
go version go1.11.5 darwin/amd64
Slobodankas-MacBook-Air:cards svlaskovic$ go build *.go
# command-line-arguments
./main.go:7:7: cards.print undefined (type []string has no field or method print)
Thank you,
Slobodanka
Adding the details to fix the error [just for future reference]:
Returning the type `deck` to cards instead of `[]string` will fix this issue. `print` accepts only `deck`. Below is the snippet
cards := _[]string_{ "Ace of Diamonds", newCard(), newCard()}
cards := **deck**{ "Ace of Diamonds", newCard(), newCard()}