-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeaf_grandmar.rb
41 lines (36 loc) · 1.27 KB
/
deaf_grandmar.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
# Whatever you say to Grandma (whatever you type in), she should respond with
# this:
#
# HUH?! SPEAK UP, SONNY!
#
# unless you shout it (type in all capitals). If you shout, she can hear you
# (or at least she thinks so) and yells back:
#
# NO, NOT SINCE 1938!
#
# To make your program really believable, have Grandma shout a different year
# each time, maybe any year at random between 1930 and 1950. (This part is
# optional and would be much easier if you read the section on Ruby’s random
# number generator on page 33.) You can’t stop talking to Grandma until you
# shout BYE.
#
# Hint 1: Don’t forget about chomp! 'BYE' with an Enter at the end is not the
# same as 'BYE' without one!
#
# Hint 2: Try to think about what parts of your program should happen over and
# over again. All of those should be in your while loop.
#
# Hint 3: People often ask me, “How can I make rand give me a number in a range
# not starting at zero?” But you don’t need it to. Is there something you could
# do to the number rand returns to you?
def deaf_grandmar
p "Say hello to grandmar:"
user = gets.chomp
until user.upcase == user || user == "BYE BYE BYE"
p "Say hello to grandmar:"
user = gets.chomp
end
year = rand(1930..1950)
p "NO, NOT SINCE #{year}!"
end
deaf_grandmar()