Created
October 21, 2015 16:16
-
-
Save siakaramalegos/78d52dca0787a92318b4 to your computer and use it in GitHub Desktop.
Ruby trivia app using each_with_index
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
# Pop trivia app | |
questions = [ | |
"Who sang Material Girl?", | |
"Which actor played Zoolander?", | |
"Who is not Michael Jackson's lover?"] | |
# store them in lowercase to make checking answers easier | |
answers = [ | |
"madonna", | |
"ben stiller", | |
"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.each_with_index do |question, index| | |
puts question | |
answer = gets.chomp.downcase | |
if answer == answers[index] | |
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