Skip to content
This repository was archived by the owner on Apr 11, 2025. It is now read-only.

Chapter 2.7 Code Example is Incorrect #71

Description

@SErvin4390

In the book, the example is shown as

`func location(name, city string) (region, continent string) {
switch city {
case "New York", "LA", "Chicago":
continent = "North America"
default:
continent = "Unknown"
}
return
}

func main() {
region, continent := location("Matt", "LA")
fmt.Printf("%s lives in %s", region, continent)
}`

But, the Go Playground shows

`package main

import "fmt"

func location(city string) (region, continent string) {
switch city {
case "Los Angeles", "LA", "Santa Monica":
region, continent = "California", "North America"
case "New York", "NYC":
region, continent = "New York", "North America"
default:
region, continent = "Unknown", "Unknown"
}
return
}

func main() {
region, continent := location("Santa Monica")
fmt.Printf("Matt lives in %s, %s", region, continent)
}
`

The Playground seems to be more correct than the code shown in the book text.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions