Forum: Ruby Dead Grandma (3 byes) -- Chris Pine Rube site

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
A99711240c185cc58558b09afa54ff72?d=identicon&s=25 Mike Wayne (mikewayne)
on 2016-12-29 09:49
I get the "right" outputs and the program exits when it's supposed to,
but just having trouble with having to start the counter of "bye" at 1.
Help on a bit of refactoring please -- or even a much-improved way to
get there?  Thank you.

bye = 1

while true
  puts "Hey Sonny! It's your lovely grandma! How are you?"
  response = gets.chomp

  if bye == 3
    puts "BYE!"
    exit 100
  elsif (response.upcase == "BYE")
    puts "Huh?! I can't hear you!"
    bye = bye + 1
    puts "bye = " + bye.to_s
  elsif response != response.upcase
      puts "No! Not since 19" + rand(30..51).to_s + "!"
      bye=0
  end
end
This topic is locked and can not be replied to.