...

/

Solution: Addition Quiz Game

Solution: Addition Quiz Game

Go over the implementation of the addition quiz game.

We'll cover the following...

Solution

count = 0 
10.times do
  num1 = rand(10)
  num2 = rand(10)
  print "#{num1} + #{num2} =" 
  answer = num1 + num2
  input = gets.chomp.to_i
  if answer == input
    puts "Correct!"
    count = count += 1 
  else
    puts "Wrong!" 
  end
end
puts "Your score is #{count}/10"
Solution for addition quiz game

Explanation

  • Lines 3–4: We generate two random numbers in the range of 0–9 by using ...