Powered by AppSignal & Oban Pro
Would you like to see your link here? Contact us

Shopping List

exercises/shopping_list.livemd

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 Tree

Text 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 the shopping_cart
  • Add "blueberries", "chocolate", and "pizza" to the shopping_cart.
  • Remove "grapes" and "walnuts" from the shopping_cart
  • Add three "banana"s to the shopping_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"]

updated_cart = shopping_cart ++ ["blueberries", "chocolate", "pizza"]
updated_cart = updated_cart -- ["grapes", "walnuts"]
updated_cart = updated_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 and 12 eggs
  • Add 2 bars_of_butter and 10 candies
  • Remove 2 bars_of_butter
  • Remove 5 candies (Notice 5 and not 10!).

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]
cart = []
cart = cart ++ [milk: 1, eggs: 12]
cart = cart ++ [butter: 2, candies: 10]

cart = cart -- [butter: 2]
cart = cart -- [candies: 10]
cart = cart ++ [candies: 5]
cart

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.

Navigation

Home Report An Issue MapsFamily Tree