Answers for Chapter 2, Working with Variables and Functions
-
You’ll find how many dollars Sarah has spent by executing the following expression:
(10 * 0.1) + (3 * 2) + 15 -
You can show Bob’s travel stats with the following code:
distance = 200 hours = 4 velocity = distance / hours IO.puts """ Travel distance: #{distance} km Time: #{hours} hours Average Velocity: #{velocity} km/h """
-
The apply_tax function should be like this:
apply_tax = fn price -> tax = price * 0.12 IO.puts "Price: #{price + tax} - Tax: #{tax}" end Enum.each [12.5, 30.99, 250.49, 18.80], apply_tax -
Your
Get Learn Functional Programming with Elixir now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.