Welcome to the Ruby Arithmetic Tutor“Hint: Look up the #print, #puts and #p statements. See which is the most appropriate here
2. Let the user introduce himselfWhat is your name?” Hello, <name>“What is your name? John Hello, John
Hint: Look up #gets and string interpolation
3. Breathing spacePress enter to begin the quiz“Hint: #gets
4. Let’s ask a questionWhat is 2 + 2?” Correct!” Wrong - the answer was 4“Hint: #puts, #gets, #if, #==
5. Five questionsHint: copy-and-paste
6. Keeping scoreYou got <n> questions right out of 5” You got 3 questions right out of 5. Your score was 60%
Hint: variables, arithmetic
7. Extract a functionask, that takes two string arguments, a question and an answerask(question, answer) should
questionanswerCorrect!” Wrong! The answer was $answer” Hint: #def, #return
8. Use the functionHint: arrays, #times, blocks
10. Change the data structureHint: questions[i] is now an array, [qi, ai]
11. Internal iterationHint: #each
12. Classesa = Question.new("What is 2 + 2?", "4")a.question #=> "What is 2 + 2?"a.answer #=> "4"Hint: #class, #initialize, #attr_reader
13. Rewrite the ‘ask’ function from Q7 to take a single Question object as a parameter
14. Rewrite the quiz to construct and then iterate over an array of 5 Question objects
ask a method of the Question class
ask(question), we want question.askHint: methods
16. Write a Question.make_addition class method that takes three numbers as arguments and returns an addition questionQuestion.make_addition(3, 4, 7) should do the same thing as Question.new("What is 3 + 4?", "7")Hint: String interpolation, #to_s
17. Make ruby calculate the answer for usHint: #raise, exceptions
19. Add a make_random_addition methodHint: #rand, have make_random_addition call make_addition rather than duplicating its code
20. Rewrite the quiz to initialize an array with five random questions instead
21. Rewrite the quiz to do away with the array altogether, generating questions as needed
22. Add a Question.make_subtraction methodQuestion.make_subtraction(10, 4) = Question.new("What is 10 - 4", "6")Hint: #begin/#rescue/#end
24. Modify your quiz to take two command line arguments, the first being either “add” or “subtract” and the second being how many questions to ask
e.g. to ask ten addition questions, run$ ruby quiz.rb add 10
Hint: ARGV, #to_i
25. Validate the command line arguments. If they are missing or wrong, print out a usage example and exit.
e.g.$ ruby quiz.rb 4 Usage: ruby quiz.rb <add|subtract> <number of questions>