Mix.install([
{:jason, "~> 1.4"},
{:kino, "~> 0.9", override: true},
{:youtube, github: "brooklinjazz/youtube"},
{:hidden_cell, github: "brooklinjazz/hidden_cell"}
])
You're going to build an app to convert metric measurements such as millimeters, centimeters, meters, and kilometers according to the following table.
[
[unit: :millimeter, value: 1, meter: 0.001],
[unit: :centimeter, value: 1, meter: 0.01],
[unit: :meter, value: 1, meter: 1],
[unit: :kilometer, value: 1, meter: 1000]
]
|> Kino.DataTable.new()
Users provide values using {from_unit, value}
tuples, and the desired unit to convert to.
Metric.convert({:centimeter, 100}, :meter)
1.0
The unit to convert from, and the unit to convert to can be either :millimeter
, :centimeter
, :meter
, or :kilometer
. The output should always be a float.
defmodule Metric do
@moduledoc """
Documentation for `Metric`
"""
@doc """
Convert one measurement to another.
We've used math values in the result
## Examples
Convert unit to meters.
iex> Metric.convert({:millimeter, 1}, :meter)
0.001
iex> Metric.convert({:centimeter, 1}, :meter)
0.01
iex> Metric.convert({:meter, 1}, :meter)
1.0
iex> Metric.convert({:kilometer, 1}, :meter)
1000
Convert meters to unit.
iex> Metric.convert({:meter, 1}, :millimeter)
1000.0
iex> Metric.convert({:meter, 1}, :centimeter)
100.0
iex> Metric.convert({:meter, 1}, :meter)
1.0
iex> Metric.convert({:meter, 1}, :kilometer)
0.001
Convert unit to unit.
iex> Metric.convert({:centimeter, 1000}, :kilometer)
0.01
iex> Metric.convert({:millimeter, 10}, :centimeter)
1.0
iex> Metric.convert({:kilometer, 10}, :centimeter)
1000000
"""
def convert(from, to) do
end
end
DockYard Academy now recommends you use the latest Release rather than forking or cloning our repository.
Run git status
to ensure there are no undesirable changes.
Then run the following in your command line from the curriculum
folder to commit your progress.
$ git add .
$ git commit -m "finish Metric Conversion exercise"
$ git push
We're proud to offer our open-source curriculum free of charge for anyone to learn from at their own pace.
We also offer a paid course where you can learn from an instructor alongside a cohort of your peers. We will accept applications for the June-August 2023 cohort soon.