-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcaffeine_script.rb
37 lines (30 loc) · 990 Bytes
/
caffeine_script.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
=begin
Complete the function caffeineBuzz, which takes a non-zero integer as it's one argument.
If the integer is divisible by 3, return the string "Java".
If the integer is divisible by 3 and divisible by 4, return the string "Coffee"
If the integer is one of the above and is even, add "Script" to the end of the string.
Otherwise, return the string "mocha_missing!"
caffeineBuzz(1) => "mocha_missing!"
caffeineBuzz(3) => "Java"
caffeineBuzz(6) => "JavaScript"
caffeineBuzz(12) => "CoffeeScript"
=end
def caffeineBuzz( n )
caffeine = ""
if n % 3 == 0
caffeine = "Java"
end
if n % 4 == 0
if caffeine != ""
caffeine = "Coffee"
end
end
if caffeine != "" && n.even?
caffeine += "Script"
end
return ( caffeine != "" ) ? caffeine : "mocha_missing!"
end
puts caffeineBuzz(1) #, "mocha_missing!")
puts caffeineBuzz(3) #, "Java")
puts caffeineBuzz(6) #, "JavaScript")
puts caffeineBuzz(12) #, "CoffeeScript")