-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexercises.rb
48 lines (37 loc) · 863 Bytes
/
exercises.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
# Exercises 5.1.1
# 1
def square(value)
value**2
end
puts "Exercise 5.1.1 - 1"
puts "The square of 5 is #{square(5)}"
# Exercises 5.3.1
# 1
def email_parts(email)
processed_email = email.downcase
processed_email.split "@"
end
puts "Exercise 5.3.1 - 1"
email_array = email_parts("[email protected]")
puts "The username and domain of [email protected] is #{email_array[0]} and #{email_array[1]}}"
# Exercises 5.4.2
# 1
def bottles(start, finish)
start.downto(finish) do |i|
if i > 1
puts "#{i} bottles of beer on the wall"
else
puts "#{i} bottle of beer on the wall"
end
end
end
puts "Exercise 5.4.2 - 2"
bottles(99,1)
# 2
puts "Exercise 5.4.2 - 2"
def bad_sandwich(contents)
puts "top bread"
contents
puts "bottom bread"
end
bad_sandwich(puts "mutton, lettuce, and tomato")