-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfizzbuzzgame.rb
67 lines (46 loc) · 964 Bytes
/
fizzbuzzgame.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
55
56
57
58
59
60
61
62
63
64
65
66
67
@correctans = 1
@stringanswer = "1"
point = 0
#method to check the answer with correctanswer
def update_correctans
if @correctans % 5 == 0
@stringanswer = "buzz"
elsif @correctans % 3 == 0
@stringanswer = "fizz"
elsif @correctans % 5 == 0 && % 3 == 0
@stringanswer = "fizzbuzz"
else
@stringanswer = @correctans.to_s
end
end
#one can choose to start or not
ans = ""
while !(ans == "yes" || ans == "no")
print "Do you want to go first (yes or no)?"
ans = gets.chomp
end
if ans == "no"
puts @correctans
@correctans += 1
update_correctans
else
puts "Please start"
end
#loop to continue the game
loop do
print "Your turn : "
u = gets.chomp.to_s
update_correctans
if u == @stringanswer
puts "good job!"
point += 1
else
break
end
@correctans += 1
update_correctans
puts "Computer : #{@stringanswer}"
@correctans += 1
end
puts "game over"
puts "You scored #{point}."