i picked up ruby 2 days ago & have been bustlin' chris pine's "learn to
program" tutorial, which goes over various aspects of ruby on a very
fundamental level. up until today, i've had relatively no problem
working out the exercises. but, as i expected, i've run into my first
significant obstacle. the exercise is as follows, "write a deaf grandma
program. whatever you say to grandma (whatever you type in), she should
respond with '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."
now, i have a pretty good idea which methods i should be using to have
grandma respond with "huh!? speak up, sonny!" whenever something is said
that is not in all capitals & i've got a firm grasp on the fact that for
the "any year at random between 1930 & 1950" i'll need to use the rand
method & define it as rand(21) + 1930. i've just been toying around with
the little i know & haven't been able to get the result i want. i
promise you i've toyed around with branching, looping, etc., but am
still not able to get even remotely close to what the exercise asks of
me.
if anyone's able to get me started in the right direction, i'd
appreciate it. there's also an extension to the exercise & it states,
"what if grandma doesn't want you to leave? when you shout 'bye', she
could pretend not to hear you. change your previous program so that you
have to shout 'bye' three times in a row. make sure to test your
program: if you shout 'bye' three times, but not in a row, you should
still be talking to grandma." but, i'll worry about that after i've got
the previous stuff squared away. thanks in advance.
···
--
Posted via http://www.ruby-forum.com/.