Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
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 = [
"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!!"
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