Closed jillrizley closed 7 years ago
I broke down the pseudo code I wrote into conditional statements for each possible winning option to check if someone won.
can you get some code to just check if the top row meets any win conditions? if you can solve that small problem you should be able to apply the logic to the rest of the board.
I have built out the full coding for checking to see if there is a winning combo, however, the console log comes up with winning right away, as it is picking up on the fact that they are equal because they are empty as opposed to picking up on being equal because they have the same specific value (X or O)
Any clues as to how to specify the value in each square
const isWinner = function () {
console.log('hey, what up!')
if (($('#1').text() === $('#2').text() && $('#1').text() === $('#3').text() && $('#1') !== '') ||
(($('#4').text() === $('#5').text() && $('#4').text() === $('#6').text() && $('#4') !== '')) ||
(($('#7').text() === $('#8').text() && $('#7').text() === $('#9').text() && $('#7') !== '')) ||
(($('#1').text() === $('#4').text() && $('#1').text() === $('#7').text() && $('#1') !== '')) ||
(($('#2').text() === $('#5').text() && $('#2').text() === $('#8').text() && $('#2') !== '')) ||
(($('#3').text() === $('#6').text() && $('#3').text() === $('#9').text() && $('#3') !== '')) ||
(($('#1').text() === $('#5').text() && $('#1').text() === $('#9').text() && $('#1') !== '')) ||
(($('#3').text() === $('#5').text() && $('#3').text() === $('#7').text() && $('#3') !== ''))
) {
console.log('wtg son!')
}
The way you wrote your conditions, this if condition should not be met if values are empty strings. For example, you are making sure that $('#1') != ''
, and doing something similar in each check to make sure the elements are not empty strings. If this condition is met every time, you could inspect the values of $('#1').text()
in the Chrome console to see if they anything besides ''
.
yeah......so I changed it back to != like we had it originally, but it gives me an "expected '!==' and instead saw '!=' " error, and still continues to console.log that any square I click is an automatic win. The values come up correctly in the console, but still getting the same problem.
updated code! had to add .text to the !== part of the statement as well as return statements for true and false
const isWinner = function () {
if (($('#1').text() === $('#2').text() && $('#1').text() === $('#3').text() && $('#1').text() !== '') ||
(($('#4').text() === $('#5').text() && $('#4').text() === $('#6').text() && $('#4').text() !== '')) ||
(($('#7').text() === $('#8').text() && $('#7').text() === $('#9').text() && $('#7').text() !== '')) ||
(($('#1').text() === $('#4').text() && $('#1').text() === $('#7').text() && $('#1').text() !== '')) ||
(($('#2').text() === $('#5').text() && $('#2').text() === $('#8').text() && $('#2').text() !== '')) ||
(($('#3').text() === $('#6').text() && $('#3').text() === $('#9').text() && $('#3').text() !== '')) ||
(($('#1').text() === $('#5').text() && $('#1').text() === $('#9').text() && $('#1').text() !== '')) ||
(($('#3').text() === $('#5').text() && $('#3').text() === $('#7').text() && $('#3').text() !== ''))
) {
return true
} else {
return false
}
}
I can get a full board of x's and o's, but I can't figure out how to write the correct function to have it tell me that there are three values in any given winning option