DEV Community

Discussion on: Pure and Simple - Tic Tac Toe with Javascript

Collapse
 
bornasepic profile image
Borna Šepić

Hey Jose, thanks for the feedback, really glad to see you like it!

Ah, I see what you mean. Well while there are 8 items in the array, array indexes start at 0, not 1 (it's a bit confusing at first but that's just how it is across all languages).

So to get the first item we need winningConditions[0], the second one is at winningConditions[1], etc.

What this means is that we only need the numbers 0 - 7 (8 numbers in total).

If you were to add the 'i <= 8' you'd actually get an error because you would be trying to access an element at index 0 of undefined a line under.