The cond
macro lets us list out a series of conditions, each with an associated code. It executes the code corresponding to the first true condition.
In the game of FizzBuzz, children count up from 1
. If the number is a multiple of three, they say “Fizz”
. For multiples of five, they say “Buzz”
. For multiples of both, they say “FizzBuzz”
. Otherwise, they say the number.
Case 1
In Elixir, we could code this as shown in the terminal below.
Run c("fizzbuzz.ex")
and FizzBuzz.upto(20)
commands to execute all the codes given below.
Get hands-on with 1400+ tech skills courses.