Skip to content

Instantly share code, notes, and snippets.

@siakaramalegos
Created October 22, 2015 14:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save siakaramalegos/ad4ad2e931cc047a5842 to your computer and use it in GitHub Desktop.
Save siakaramalegos/ad4ad2e931cc047a5842 to your computer and use it in GitHub Desktop.
Same trivia app but using a hash instead of 2 arrays
# Pop trivia app
questions_answers = {
"Who sang Material Girl?" => "madonna",
"Which actor played Zoolander?" => "ben stiller",
"Who is not Michael Jackson's lover?" => "billie jean"
}
puts "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
puts " Welcome to Sia's Really Cool Trivia App"
puts "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
puts "\nLet's get started...\n"
# Do for all questions
# Ask a question
# Get an answer and check it
# Tell them if the answer is correct
questions_answers.each do |question, answer|
puts question
user_answer = gets.chomp.downcase
if user_answer == answer
puts "CORRECT!!"
else
puts "I'm sorry, you're not SMAHT."
end # ends if
end # ends the loop
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment