8 Answers
New Answer7/4/2022 3:42:23 PM
Harshita Kumari8 Answers
New AnswerThis is a possible way (a fast made solution based on your code): https://code.sololearn.com/WHqBk1w2Y9bt/?ref=app
The most important is this: btn.addEventListener('click', function (e){ const id = e.target.id; if (player1 == 1) { btn.innerHTML = "X"; array_winnings[id] = "X"; x_win(); player1 = 0; } else { btn.innerHTML = "0"; array_winnings[id] = "0"; y_win(); player1 = 1; } }); Here I get id of clicked button, which number will made to the index of array_winnings. And there I save the player character X or O and then call player specific win function to check if this player won sfter its move.
JaScript Prefer giving hints for the OP to find the solution. It helps in the learning process.
This is an Ari from W3school https://www.w3schools.com/jsref/jsref_concat_array.asp#:~:text=Definition%20and%20Usage,not%20change%20the%20existing%20arrays. Hope this helps.
Sololearn Inc.
535 Mission Street, Suite 1591Send us a message