CLI Trivia

Iterators, arrays, hashes and allllll the variables

def self.random_question(question)puts "#{question.question}"
answers = []
answers << question.correct_answer
answers << question.incorrect_answers
randomized = answers.flatten.shuffle
q_a = {q: question, a: randomized}
randomized.each.with_index do |answer, i|
puts "#{i + 1}. #{answer}"
def self.check_answer(q_a, input)
true if q_a[:q].correct_answer == input
def check_question
input = gets.strip.to_i - 1
answer = TriviaQuestion.check_answer(@q_a, @q_a[:a][input])
if answer && input.between?(0, 3)
puts "You got it!"


Pry is your best friend!!!

Instance Variables

@q = sorted_categories[input - 1]
@qs = TriviaQuestion.questions_in_category(@q.category)




Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Fix Common Gephi Errors

Android fundamentals 05.2: Cards and colors

AWS Greengrass on Raspberry Pi: Creating Core and Node Devices

FPGA meets Apache Arrow — Efficient in-memory columnar data communication with FPGA-based ML…

Monitoring Tesla Solar and Powerwall with Prometheus

This week in #Scala (Feb 7, 2022)

How to Hack C++ Code

My Approach Towards Project Weeks…

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store


More from Medium

Yalla, bye.

04. Claire

Everything you need to know about Leo — part 2