I make Yahtzee game in Ruby with shoes when I press the "Two" button, the code should count the number of times the value 2 occurs in the array. For each instance of the value 2 that appears, the score is increased by 2.
This code works for the selected number of cases, but in other cases, such as @array = [2,1,2,2,3] # there are three 2 in the array, so the rating should 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
end
source
share