-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path3_conditionals.rb
57 lines (53 loc) · 1.21 KB
/
3_conditionals.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
52
53
54
55
56
57
# return 'fizz' if the number is divisible by 3
# return 'buzz' if the number is divisible by 5
# return 'fizzbuzz' if the number is divisible by 15
# return '1' if the number is not divisible by 3, 5 or 15
# clue - you can check divisibility using modulo (%)
def fizz_buzz(number)
if number % 15 == 0
return "fizzbuzz"
elsif number % 5 == 0
return "buzz"
elsif number % 3 == 0
return "fizz"
else
return "1"
end
end
# if the greeting is 'good morning'
# return 'good morning to you too'
# if the greeting is 'hello'
# return 'hi'
# if the greeting is anything else
# return the greeting that was received
def reply_to(greeting)
if greeting == "good morning"
return "good morning to you too"
elsif greeting == "hello"
return "hi"
else
return greeting
end
end
# when the number is greater than or equal to 10
# deduct 10 and return the result
# when the number is below 10
# return the number
def deduct_10_if_possible(number)
if number > 9
return number - 10
else
return number
end
end
# if the number is below 100
# return 100
# if the number is above 100
# return the number
def top_up_to_100(number)
if number < 100
return 100
else
return number
end
end