Exercises & activities from the go workshop provided by Packt: https://courses.packtpub.com/courses/go
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

26 lines
335 B

  1. package main
  2. import "fmt"
  3. func main() {
  4. for i := 1; i <= 15; i++ {
  5. n, s := fizzBuzz(i)
  6. fmt.Printf("Results: %d %s\n", n, s)
  7. }
  8. }
  9. func fizzBuzz(i int) (int, string) {
  10. switch {
  11. case i%15 == 0:
  12. return i, "FizzBuzz"
  13. case i%3 == 0:
  14. return i, "Fizz"
  15. case i%5 == 0:
  16. return i, "Buzz"
  17. }
  18. return i, ""
  19. }