-
Notifications
You must be signed in to change notification settings - Fork 0
/
exercise6.rb
51 lines (41 loc) · 1.08 KB
/
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
48
49
50
51
#Arrays
#create a method to show the list
def present ( grocery_list )
#present grocery list with an asterisk in front of each item, and one item per line
grocery_list.each do |grocery|
puts "* #{grocery}"
end
end
#grocery list
grocery_list = ["carrots" , "toilet paper" , "apples" , "salmon" , "bananas"]
#add rice to the list
grocery_list << "rice"
grocery_list << "peach"
present ( grocery_list )
#count the list
puts grocery_list.count
#if bananas
def buy_or_nah(bananas , g)
g.each do |grocery|
if ( grocery == bananas )
return "You need to pick up bananas"
end
end
return "You dont need to pick up bananas today"
end
#inculde
def include_bananas(bananas , g)
if g.include?(bananas)
puts "You need to pick up bananas"
else
puts "You dont need to pick up bananas today"
end
end
grocery_list2 = ["bread"]
puts buy_or_nah("bananas", grocery_list)
buy_or_nah("bananas", grocery_list2)
include_bananas("bananas" , grocery_list)
#display the second item in the list
puts grocery_list [ 1 ]
#display the list alphabetically
present (grocery_list).sort