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

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
Please log in before posting. Registration is free and takes only a minute.
Existing account

NEW: Do you have a Google/GoogleMail, Yahoo or Facebook account? No registration required!
Log in with Google account | Log in with Yahoo account | Log in with Facebook account
No account? Register here.