Grandma has hearing issues 'cos she's getting old. All she does is
answer my questions with a phrase "NO NOT SINCE 1938'. If I don't
yell(.upcase), she's gonna tell me to speak up. If I yell without a
question mark, she'll tell me "THAT'S NOT A QUESTION!". I write a
program for this scenario and anytime I yell with or without a question
mark, she tells me "THAT'S NOT A QUESTION!"
What am I doing wrong or at least what am I missing?
question = ''
puts 'Ask grandma something...'
while question != 'BYE!'
question = gets.chomp
if question != question.upcase
puts 'HUH?! SPEAK UP, SONNY!'
elsif question == question.upcase+'?'
puts 'NO, NOT SINCE 1938!'
elsif question == question.upcase
puts 'THAT\'S NOT A QUESTION!'
elsif question == 'BYE!'
puts 'BYE!'
end
end
Grandma has hearing issues 'cos she's getting old. All she does is
answer my questions with a phrase "NO NOT SINCE 1938'. If I don't
yell(.upcase), she's gonna tell me to speak up. If I yell without a
question mark, she'll tell me "THAT'S NOT A QUESTION!". I write a
program for this scenario and anytime I yell with or without a question
mark, she tells me "THAT'S NOT A QUESTION!"
What am I doing wrong or at least what am I missing?
if question != question.upcase
puts 'HUH?! SPEAK UP, SONNY!'
elsif question == question.upcase+'?'
puts 'NO, NOT SINCE 1938!'
elsif question == question.upcase
puts 'THAT\'S NOT A QUESTION!'
elsif question == 'BYE!'
puts 'BYE!'
end
end
Hint: the condition that question has to be equal to question.upcase +
'?' is wrong. Check here Class: String (Ruby 1.8.7) and see if you can
find a method that tells you if the string ends with (hint, hint) a
question mark.
Jesus.
···
On Wed, Aug 31, 2011 at 2:30 PM, Samuel Mensah <sasogeek@yahoo.com> wrote:
Grandma has hearing issues 'cos she's getting old. All she does is
answer my questions with a phrase "NO NOT SINCE 1938'. If I don't
yell(.upcase), she's gonna tell me to speak up. If I yell without a
question mark, she'll tell me "THAT'S NOT A QUESTION!". I write a
program for this scenario and anytime I yell with or without a question
mark, she tells me "THAT'S NOT A QUESTION!"
What am I doing wrong or at least what am I missing?
I just had a go with this and tried for at least an hour before getting
here. I read a few responses and gave it another go, read some more and
finally got it. It looks a lot like the previous post but a little
change here or there, not much though. I noticed my "rand" part with the
dates is different from everyone elses but it works just how i imagined
it too. And the assigning of response I picked up from aother person
that made it easier for me to understand is tucked nicly inside the
first action as to include it in the looping effect.
puts 'Hi Sweety, it\'s Grandma!'
bye = 0
while bye < 3
if ((response = gets.chomp) == "BYE")
puts "GOOD BYE, SONNY!"
bye = (bye+1)
end
if (response != response.upcase)
puts 'HUH?! SPEAK UP, SONNY!'
bye = 0
end
if (response == response.upcase and response != "BYE")
puts 'NO, NOT SINCE '+(rand(1930..1951)).to_s+'!'
bye = 0
end
end
This sure was a tough one without knowing bout all the functions you
needed to know. There was a lot left to imagination, like the thing that
pushed my RUBY into being finished was the "AND" function in my 3rd if
statement. When ever I would type "BYE" it would also tell me "NO, NOT
SINCE 19xx! and then also GOOD BYE SONNY!..... I just couldn't figure
out how to exclude something from the "puts" and it also would make the
bye value set to 0 when it used both responses cause I set it so if
"BYE" wasn't used it would reset the value of "BYE" back to zero. All in
all this excerise was almost easy enough to do it without help or hints
but not quite. Made me want to know though and pushed me to try really
hard but I just feel with the info adding up to the "TRY IT OUT" part in
the pickaxe just didn't stick well enough or just didn't have the parts
told to you yet? Might just be me but I definately struggled.
Try like this: question == question.upcase[0...-1]+'?'
That did the trick thanks a lot. That said though, I don't understand
what the "" is all about as I'm a beginner programmer, I haven't come
across that in my studies as of yet until now. You mind explaining what
it means and what it did?
Nice, I started programming with Chris Pine's book too a little under a
year ago. I still have fond memories of the exercises in there. Keep at
it, man!
On Aug 31, 2011, at 11:28, Samuel Mensah <sasogeek@yahoo.com> wrote:
Try like this: question == question.upcase[0...-1]+'?'
That did the trick thanks a lot. That said though, I don't understand
what the "" is all about as I'm a beginner programmer, I haven't come
across that in my studies as of yet until now. You mind explaining what
it means and what it did?