Created
May 1, 2012 19:38
-
-
Save jtsagata/2570779 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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