Skip to content

Commit

Permalink
Create fizzbuzz.go
Browse files Browse the repository at this point in the history
  • Loading branch information
rerichardjr authored Sep 26, 2023
1 parent 76e2dc0 commit f07d61a
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions fizzbuzz.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
func fizzBuzz(n int) []string {
answer := make([]string, n)
for i := 1; i <= n; i++ {
mod3 := i % 3
mod5 := i % 5
if mod3 == 0 && mod5 == 0 {
answer[i-1] = "FizzBuzz"
continue
}
if mod3 == 0 {
answer[i-1] = "Fizz"
continue
}
if mod5 == 0 {
answer[i-1] = "Buzz"
continue
}
answer[i-1] = strconv.Itoa(i)
}
return answer
}

0 comments on commit f07d61a

Please sign in to comment.