2022-08-14 09:35:28 +00:00
|
|
|
package main
|
|
|
|
|
2022-08-14 10:23:47 +00:00
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"strconv"
|
|
|
|
)
|
2022-08-14 09:35:28 +00:00
|
|
|
|
|
|
|
func FizzBuzz() {
|
|
|
|
for i := 0; i < 20; i++ {
|
2022-08-14 10:20:46 +00:00
|
|
|
fmt.Println(fizzOrBuzz(i))
|
2022-08-14 09:35:28 +00:00
|
|
|
}
|
|
|
|
}
|
2022-08-14 09:42:33 +00:00
|
|
|
|
|
|
|
func fizzOrBuzz(number int) string {
|
2022-08-14 10:42:59 +00:00
|
|
|
out := handle3(number) + handle5(number)
|
|
|
|
if out != "" {
|
|
|
|
return out
|
2022-08-14 10:27:32 +00:00
|
|
|
}
|
|
|
|
|
2022-08-14 10:23:47 +00:00
|
|
|
return strconv.Itoa(number)
|
2022-08-14 09:42:33 +00:00
|
|
|
}
|
2022-08-14 10:36:57 +00:00
|
|
|
|
2022-08-14 10:37:52 +00:00
|
|
|
func handle5(number int) string {
|
|
|
|
if number%5 == 0 {
|
|
|
|
return "Buzz"
|
|
|
|
}
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
|
2022-08-14 10:36:57 +00:00
|
|
|
func handle3(number int) string {
|
|
|
|
if number%3 == 0 {
|
|
|
|
return "Fizz"
|
|
|
|
}
|
|
|
|
return ""
|
|
|
|
}
|