Skip to content

Instantly share code, notes, and snippets.

@jtsagata
Created May 1, 2012 19:38
Show Gist options
  • Save jtsagata/2570779 to your computer and use it in GitHub Desktop.
Save jtsagata/2570779 to your computer and use it in GitHub Desktop.
options = %w(spaghetti beaf chicken salads fruit)
favs = []
def valid_answer(reply)
%w(yes no).include? reply
end
def ask question
reply = ""
until valid_answer(reply)
print "#{question} (please answer 'yes' or 'no') :"
reply = gets.chomp.downcase
end
return false if reply == "no"
true
end
puts "Welcome to the test! please answer all questions with 'yes' or 'no'.\n"
options.each do |food|
answer = ask "Do you like #{food}"
favs.push answer
end
puts "\n#{favs}\n"
puts "Thank you for the survey!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment