Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Go Language

In golf, players need to get the ball in the hole within a target number of strokes, called "par".

This one got me a bit stuck but after reading some documentation was able to solve this one. Wanted to post this if anyone else has any trouble that they can find an answer here as I don't believe this one has been answered yet. The switch statement below is straightforward but what I got stuck on was making sure that I was returning the value of each after it was evaluated.

https://teamtreehouse.com/library/go-language-overview/flow-control/switch-statements

package golf

import "fmt"

func ShotsDescription(par int, shots int) string {
    shotsOverPar := shots - par
    // YOUR CODE HERE
    switch shotsOverPar {
    case 1:
        fmt.Println("bogey")
        return "bogey"
    case 0:
        fmt.Println("par")
        return "par"
    case -1:
        fmt.Println("birdie")
        return "birdie"
    case -2:
        fmt.Println("eagle")
        return "eagle"
    default:
        fmt.Println("no description")
        return "no description"
    }
}
Steven Parker
Steven Parker
229,788 Points

Can you provide a link to the source where this task comes from?

1 Answer

Solved