Introducing functions

We can think of functions as subprograms within our program; they receive an input, do some computation, and then return an output. The function body is where we write expressions to do a computation. The last expression value in the function body is the function’s output. Functions are useful for reusing expressions. Let’s start with a simple example in which we’ll build messages to say hello to Ana, John, and the world. But first, try typing this in the IEx at the end of this lesson:

iex> "Hello, Mary!"
#Output -> "Hello, Mary!"

iex> "Hello, John!"
#Output -> "Hello, John!"

iex> "Hello, World!"
#Output -> "Hello, World!"

Get hands-on with 1200+ tech skills courses.