Can anybody tell me how to join my array to id in javascript | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Can anybody tell me how to join my array to id in javascript

https://code.sololearn.com/WUQ8VCsMkVkI/?ref=app

4th Jul 2022, 3:42 PM
Harshita Kumari
Harshita Kumari - avatar
8 Answers
+ 2
This is a possible way (a fast made solution based on your code): https://code.sololearn.com/WHqBk1w2Y9bt/?ref=app
4th Jul 2022, 4:45 PM
JaScript
JaScript - avatar
+ 2
JaScript can you explain what changes have you done and what were my faults
4th Jul 2022, 4:51 PM
Harshita Kumari
Harshita Kumari - avatar
+ 2
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.
4th Jul 2022, 5:01 PM
JaScript
JaScript - avatar
+ 2
JaScript Prefer giving hints for the OP to find the solution. It helps in the learning process.
4th Jul 2022, 5:50 PM
Emerson Prado
Emerson Prado - avatar
+ 1
JaScript thank you
4th Jul 2022, 4:47 PM
Harshita Kumari
Harshita Kumari - avatar
+ 1
Welcome & happy coding!
4th Jul 2022, 4:50 PM
JaScript
JaScript - avatar
+ 1
JaScript okay thanks
4th Jul 2022, 5:02 PM
Harshita Kumari
Harshita Kumari - avatar
+ 1
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.
6th Jul 2022, 1:03 PM
Gray Adamson
Gray Adamson - avatar