27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
# File 'lib/kidomath.rb', line 27
def self.ask(level=1)
operations = ['+','-','*','/']
case level
when 1
rand1 = 1 + rand(10)
rand2 = 1 + rand(10)
randop = operations[rand(operations.length)].chomp
if rand1 > rand2
res = rand1.send(randop,rand2)
print "#{rand1} #{randop} #{rand2} = "
else
res = rand2.send(randop,rand1)
print "#{rand2} #{randop} #{rand1} = "
end
kid_said = gets.to_i
if res == kid_said
print "Correct answer, here are the gems for you :) keep it up! "
Cadbury.gems(res)
print "\n"
else
puts "Sorry the anwser is #{res} :("
end
when 2
rand1 = 1 + rand(100)
rand2 = 1 + rand(100)
randop = operations[rand(operations.length)].chomp
res = rand1.send(randop,rand2)
print "#{rand1} #{randop} #{rand2} = "
kid_said = gets.to_i
if res == kid_said
print "Correct answer, here are the gems for you :) keep it up! "
Cadbury.gems(10)
print "\n"
else
puts "Sorry the anwser is #{res} :("
end
when 3
rand1 = 1 + rand(200)
rand2 = 1 + rand(200)
randop = operations[rand(operations.length)].chomp
res = rand1.send(randop,rand2)
print "#{rand1} #{randop} #{rand2} = "
kid_said = gets.to_i
if res == kid_said
print "Correct answer, here are the gems for you :) keep it up! "
Cadbury.gems(10)
print "\n"
else
puts "Sorry the anwser is #{res} :("
end
end
end
|