Arithmetic Tutor

1. Let’s introduce ourselves

Hint: Look up the #print, #puts and #p statements. See which is the most appropriate here

2. Let the user introduce himself e.g.
What is your name?
John
Hello, John

Hint: Look up #gets and string interpolation

3. Breathing space

Hint: #gets

4. Let’s ask a question

Hint: #puts, #gets, #if, #==

5. Five questions

Hint: copy-and-paste

6. Keeping score e.g.
You got 3 questions right out of 5. 
Your score was 60%

Hint: variables, arithmetic

7. Extract a function

Hint: #def, #return

8. Use the function 9. Numeric loop

Hint: arrays, #times, blocks

10. Change the data structure

Hint: questions[i] is now an array, [qi, ai]

11. Internal iteration

Hint: #each

12. Classes

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

15. Make ask a method of the Question class

Hint: methods

16. Write a Question.make_addition class method that takes three numbers as arguments and returns an addition question

Hint: String interpolation, #to_s

17. Make ruby calculate the answer for us 18. Validate the inputs to make_addition

Hint: #raise, exceptions

19. Add a make_random_addition method

Hint: #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 method 23. Add a Question.make_random_subtraction method

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>