Just a quick one, in handleResultValidation(), the for loop I believe should be 'i <= 8' since there is 8 possible combinations in total.
I'm assuming that the index it's 7, but if you don't put 8 then playing diagonally from top right corner to bottom left won match as a win.
Other than that, great post, very easy to follow and the explanations are top notch!
Cheers!
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.
Damn! I was wrong being right, but you are most deffo right. I added an extra winning move, so my array.length was longer than yours.
My bad, sorry.
Thanks for the article!
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Hey Borna, amazing post.
Just a quick one, in handleResultValidation(), the for loop I believe should be 'i <= 8' since there is 8 possible combinations in total.
I'm assuming that the index it's 7, but if you don't put 8 then playing diagonally from top right corner to bottom left won match as a win.
Other than that, great post, very easy to follow and the explanations are top notch!
Cheers!
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.
Damn! I was wrong being right, but you are most deffo right. I added an extra winning move, so my array.length was longer than yours.
My bad, sorry.
Thanks for the article!