-
Notifications
You must be signed in to change notification settings - Fork 0
/
dry.rb
48 lines (33 loc) · 838 Bytes
/
dry.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# require 'pry'
# class ShoppingCart
# attr_accessor :coupon
# def checkout
# total = 0
# #the shopping_cart method holds an array of all the user's items
# shopping_cart.each do |item|
# total += item.price
# end
# binding.pry
# if coupon
# total = total - total * coupon / 100.00
# end
# total
# end
# end
require 'pry'
def checkout(discount=0)
total = 0
#the shopping_cart method holds an array of all the user's items
shopping_cart.each do |item|
total += item.price
end
if discount == 10
total = total - total * 10 / 100.00
elsif discount == 20
total = total - total * 20 / 100.00
elsif discount == 50
total = total - total * 50 / 100.00
end
total
end
binding.pry