I'm making a Yahtzee game in Ruby using Shoes when I click Button "Two" the code is suppose to count the amount of times the value 2 occurs in an array. For every instance of the value 2 that appears, the score is incremented by 2.
This code works for a select amount of cases but on other cases like @array = [2,1,2,2,3] # there are three 2's in the array so the score is suppose to be 6, but instead my code returns 4... why?
button " twos " do
@array.each_with_index do |value, index|
if (@array[index] == 2)
@score = @score + 2
@points = @score + 2
end #if
end #loop end #button