You just need to return the value of counter at the end of your function and also change your = to ==.
= is for assignment. == is for comparison.
def turn_count(board)
counter = 0
board.each do |turn|
if turn.downcase == "x" || turn.downcase == "o"
counter += 1
puts "#{counter}"
end
end
counter
end
I've also added the downcase method so that you're comparison is consistent. Otherwise, if you're looking for x but the array contains an X, you won't get a match.
SIDENOTE:
I changed index to turn because what you're declaring for that each loop is not actually an index. It's the array element itself.
If you wanted to use the index in the loop, you'd need to do something like:
board.each_with_index do |turn, index|
SIDENOTE #2:
You could also do the each loop as a super clean one-liner:
board.each { |t| counter +=1 if ['x', 'o'].include?(t.downcase) }
Just another option. :-)
counterat the end of your method?