From 76ecc7b68c3d2ff4f9678567ac23e3f6f8c677af Mon Sep 17 00:00:00 2001 From: Zesky665 Date: Mon, 1 Aug 2016 11:42:37 +0200 Subject: [PATCH] More specific answer The given answer failed to account for qty values above 20. In the case of the "banana" item, it returned an freeQty value of 6. In the exercise description it states "Purchases of 5 or more receive 1 free. Purchases of 10 or more receive 3 free". The original code added +3 for each 10 instead of +3 if qty is >= 10. Great course otherwise :) . --- .../CompletedExercises/Exercise1.elm | 21 +++++++++++-------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/03 type-annotations/CompletedExercises/Exercise1.elm b/03 type-annotations/CompletedExercises/Exercise1.elm index 2e5f309..6373fb9 100644 --- a/03 type-annotations/CompletedExercises/Exercise1.elm +++ b/03 type-annotations/CompletedExercises/Exercise1.elm @@ -7,17 +7,20 @@ cart = [ { name = "Lemon", qty = 1, freeQty = 0 } , { name = "Apple", qty = 5, freeQty = 0 } , { name = "Pear", qty = 10, freeQty = 0 } + , { name = "Banana", qty = 20, freeQty = 0 } ] -free minQty freeQty item = - if item.freeQty == 0 && minQty > 0 then - { item | freeQty = item.qty // minQty * freeQty } - else - item - +free item = + if item.qty >= 10 && item.freeQty == 0 then + {item | freeQty = 3} + else if item.qty >= 5 && item.freeQty == 0 then + {item | freeQty = 1} + else + item main = - List.map ((free 10 3) >> (free 5 1)) cart - |> toString - |> Html.text + List.map free cart + |> toString + |> Html.text +