-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaddition_flashcard.rb
54 lines (44 loc) · 1.1 KB
/
addition_flashcard.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
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
require 'rubygems'
require 'chronic_duration'
#d = 300 # seconds
#d.times {|x| sleep 1; puts ChronicDuration.output(d - x)}
$total = 0;
$num = 5;
$wrong = 0;
$correct = 0;
#$start_time = Time.now;
#$total_time = Time.now - $start_time;
puts Time.now
until $total == $num do
card1 = rand(10)
card2 = rand(10)
correct_answer = card1 + card2
puts "\n\nWhat is #{card1} + #{card2}?"
submitted_answer = gets.chomp
integer_answer = submitted_answer.to_i
if correct_answer != integer_answer then
puts "Wrong\n";
$wrong += 1;
else
puts "Correct\n";
$correct += 1;
end
$total += 1;
end
if $wrong > $correct then
puts "You got more wrong than right. You need more practice!\n\n";
elsif $wrong == 0 then
puts "You are a rock star!\n"
puts "You got all #{$total} cards right!\n\n"
elsif $wrong < $correct then
puts "You got #{$wrong} wrong out of #{$total}.\n\n"
puts "You got more right than wrong. Nice job.\n\n"
else
#puts "You got #{$wrong} wrong out of #{$total}.\n\n"
#puts "You answered #{$correct} correctly. Good job!\n\n"
end
=begin
total_number
number_correct
# elapsed time
=end