Shopping List
Mix.install([
{:jason, "~> 1.4"},
{:kino, "~> 0.9", override: true},
{:youtube, github: "brooklinjazz/youtube"},
{:hidden_cell, github: "brooklinjazz/hidden_cell"}
])
Navigation
Home Report An Issue MapsFamily TreeText Shopping List
You are creating a shopping list app. Users have the ability to add items into their shopping_cart
.
Each item is represented as a string.
In the Elixir cells below, use ++
and --
to add the items shown.
-
Add
"grapes"
,"walnuts"
, and"apples"
to theshopping_cart
-
Add
"blueberries"
,"chocolate"
, and"pizza"
to theshopping_cart
. -
Remove
"grapes"
and"walnuts"
from theshopping_cart
-
Add three
"banana"
s to theshopping_cart
Example solution
shopping_cart = []
shopping_cart = shopping_cart ++ ["grapes", "walnuts", "apples"]
shopping_cart = shopping_cart ++ ["blueberries", "chocolate", "pizza"]
shopping_cart = shopping_cart -- ["grapes", "walnuts"]
shopping_cart = shopping_cart ++ ["banana", "banana", "banana"]
Enter your solution below.
shopping_cart = []
shopping_cart = shopping_cart ++ ["grapes", "walnuts", "apples"]
shopping_cart = shopping_cart ++ ["blueberries", "chocolate", "pizza"]
shopping_cart = shopping_cart -- ["grapes", "walnuts"]
shopping_cart = shopping_cart ++ ["banana", "banana", "banana"]
Text Shopping List With Quantities
Users of your shopping list app have asked that they be able to include the quantity of each item to make adding many items easier.
In the Elixir cell below, use a keyword list in the format [item: quantity]
to add or remove
items from the shopping_cart
-
Add
1
milk
and12
eggs
-
Add
2
bars_of_butter
and10
candies
-
Remove
2
bars_of_butter
-
Remove
5
candies
(Notice5
and not10
!).
Example solution
shopping_cart = []
shopping_cart = shopping_cart ++ [milk: 1, eggs: 12]
shopping_cart = shopping_cart ++ [bars_of_butter: 2, candies: 10]
shopping_cart = shopping_cart -- [bars_of_butter: 2]
shopping_cart = shopping_cart -- [candies: 10]
shopping_cart = shopping_cart ++ [candies: 5]
shopping_cart = []
shopping_cart = shopping_cart ++ [milk: 1, eggs: 12]
shopping_cart = shopping_cart ++ [bars_of_butter: 2, candies: 10]
shopping_cart = shopping_cart -- [bars_of_butter: 2]
shopping_cart = shopping_cart -- [candies: 10]
shopping_cart = shopping_cart ++ [candies: 5]
Commit Your Progress
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 Shopping List 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.