Skip to content

Instantly share code, notes, and snippets.

@siakaramalegos
Created October 21, 2015 16:16
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/78d52dca0787a92318b4 to your computer and use it in GitHub Desktop.
Save siakaramalegos/78d52dca0787a92318b4 to your computer and use it in GitHub Desktop.
Ruby trivia app using each_with_index
# 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