# Quick help with project

**URL:** <https://forum.freecodecamp.org/t/quick-help-with-project/181518>\
**Category:** General\
**Created:** [March 24, 2018, 11:24pm UTC](https://forum.freecodecamp.org/t/quick-help-with-project/181518 "2018-03-24T23:24:59Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![tpedora](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/tpedora/32/81980_2.png) [@tpedora](https://forum.freecodecamp.org/u/tpedora)\
**Post date:** [March 24, 2018, 11:25pm UTC](https://forum.freecodecamp.org/t/quick-help-with-project/181518/1 "2018-03-24T23:25:00Z")

</div>

Good evening all! I’m trying my hand at a x’s and o’s game. I’m stuck on the click logic. Here’s what I have.

let playerOne = true;  
let box = document.querySelectorAll(":scope .box");

box.addEventListener(“click”, function() {  
if (playerOne) {  
box.textContent = “X”;  
playerOne = false;  
} else {  
box.textContent = “O”;  
playerOne = true;  
}  
});

My guess is that the .querySelectorAll isn’t functioning as I would expect it too. I’m trying to use it to select 9 .box classes in my html file.

Thank you!

---

<div class="post-metadata">

**Author:** ![SpaniardDev](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/spaniarddev/32/89850_2.png) [@SpaniardDev](https://forum.freecodecamp.org/u/SpaniardDev)\
**Post date:** [March 24, 2018, 11:39pm UTC](https://forum.freecodecamp.org/t/quick-help-with-project/181518/2 "2018-03-24T23:39:52Z")

</div>

Hi,

querySelectorAll() selects ALL those boxes. You’re not targeting one of them alone for each event.

Happy coding!

---

<div class="post-metadata">

**Author:** ![tpedora](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/tpedora/32/81980_2.png) [@tpedora](https://forum.freecodecamp.org/u/tpedora)\
**Post date:** [March 24, 2018, 11:51pm UTC](https://forum.freecodecamp.org/t/quick-help-with-project/181518/3 "2018-03-24T23:51:13Z")

</div>

Thank you! thats good to know. I’m guessing a the .addEventListener can be used inside a for loop … that would go through each of the array items?

---

<div class="post-metadata">

**Author:** ![SpaniardDev](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/spaniarddev/32/89850_2.png) [@SpaniardDev](https://forum.freecodecamp.org/u/SpaniardDev)\
**Post date:** [March 24, 2018, 11:57pm UTC](https://forum.freecodecamp.org/t/quick-help-with-project/181518/4 "2018-03-24T23:57:50Z")

</div>

Yes. Don’t forget to check on MDN, Stackoverflow… to try to solve your problems, that will make you a better developer.

---

<div class="post-metadata">

**Author:** ![abalducci](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/abalducci/32/78525_2.png) [@abalducci](https://forum.freecodecamp.org/u/abalducci)\
**Post date:** [March 25, 2018, 12:07am UTC](https://forum.freecodecamp.org/t/quick-help-with-project/181518/5 "2018-03-25T00:07:32Z")

</div>

Also keep in mind you can alternately, given in this case we have a small subset (only 9) options, create the divs as id ‘box1’, ‘box2’, ‘box3’-- Or ‘box00’ , ‘box01’, ‘box02’, and then when you are in JS concatenate on the present selector (i.e. say a double for loop of x and y, size three by three and each selector you concat the name).

This might save you some JS code being able to repeat the operation, but it is just an idea. There are many ways to go about solving this problem.

---

<div class="post-metadata">

**Author:** ![tpedora](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/tpedora/32/81980_2.png) [@tpedora](https://forum.freecodecamp.org/u/tpedora)\
**Post date:** [March 25, 2018, 4:27am UTC](https://forum.freecodecamp.org/t/quick-help-with-project/181518/6 "2018-03-25T04:27:06Z")

</div>

Thanks for all the help! I’m trying to figure out how to iterate over it with a for loop, but am getting stuck! I know I need to find a way to select the individual objects and associate the eventListener to it.

for (i = 0; i \< 9; i++) {  
let buttonClick = [];  
if (playerOne) {  
this.addEventListener(“click”, function() {  
this.textContent = “x”;  
playerOne = false;  
})};

This is what I’ve tried, and the farthest Ive gotten, but I know I’m doing something wrong. Any tips to get me on the right track … without making the solution a gimme? I need to figure this out myself 🙂

Thanks all!

---

<div class="post-metadata">

**Author:** ![tpedora](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/tpedora/32/81980_2.png) [@tpedora](https://forum.freecodecamp.org/u/tpedora)\
**Post date:** [March 25, 2018, 9:35pm UTC](https://forum.freecodecamp.org/t/quick-help-with-project/181518/7 "2018-03-25T21:35:13Z")

</div>

Alright! Thank you for the help … one more question popped up. I’ve created 9 empty boxes, that I’ve styled, however no matter what I do with the padding/margin … whenever a user clicks into the box, and an X or O gets placed, the box size adjusts. Any help would be appreciated!

---

<div class="post-metadata">

**Author:** ![ILM](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/ilm/32/363239_2.png) [@ILM](https://forum.freecodecamp.org/u/ILM)\
**Post date:** [January 17, 2021, 8:23pm UTC](https://forum.freecodecamp.org/t/quick-help-with-project/181518/8 "2021-01-17T20:23:57Z")

</div>

Closed on January 17, 2021, 8:23pm UTC


