-
Notifications
You must be signed in to change notification settings - Fork 0
/
exercise6.rb
55 lines (32 loc) · 843 Bytes
/
exercise6.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
47
grocery_list = ["carrots", "toilet paper", "apples", "salmon"]
def grocerydisplay(grocery_list)
grocery_list.each do |item|
puts "* #{item}"
end
end
def add_grocery(grocery_list, item)
grocery_list.push(item)
grocerydisplay(grocery_list)
end
def count_grocery(grocery_list)
num = grocery_list.length
puts "You have #{num} grocery items"
end
def include_grocery(grocery_list)
if grocery_list.include? ("banana")
puts "You don't need to pick up bananas"
else
puts "You need to pick up bananas"
end
end
def grocery_sort(grocery_list)
sorted_list = grocery_list.sort
grocerydisplay(sorted_list)
end
add_grocery(grocery_list, "rice")
count_grocery(grocery_list)
include_grocery(grocery_list)
puts grocery_list[1]
grocerydisplay(grocery_list.sort)
grocery_list.delete("salmon")
grocerydisplay(grocery_list)