Use of the cond Keyword

Understand how to implement different conditions using the cond macro.

We'll cover the following

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 1200+ tech skills courses.