I get that error while naming variables in my loop. The point of the method is to print the index position of the only element with unique parity in the array. For example the method should print "3" for the following input array because it is the only odd number and everything else is even: [2, 4, 6, 3, 8, 10]. More specifically, it points out the error to "Odd" and "Even" variables below ("main.rb:7: dynamic constant assignment Odd = numbers[i] % 2 == 1").
def test(numbers)
i=1
countOdd = 0
countEven = 0
Odd = numbers[i] % 2 == 1
Even = numbers[i] % 2 == 0
while i < numbers.length
if Odd
countOdd += 1
else countEven +=1
end
i+=1
end
if countEven == 1
print Odd.index
else print Even.index
end
end