MCPcopy Create free account
hub / github.com/Vishal-raj-1/Awesome-JavaScript-Projects / handleCellClick

Function handleCellClick

assets/js/ConnectFour.js:412–435  ·  view source on GitHub ↗
(e)

Source from the content-addressed store, hash-verified

410};
411
412const handleCellClick = (e) => {
413 if (!gameIsLive) return;
414
415 const cell = e.target;
416 const [rowIndex, colIndex] = getCellLocation(cell);
417
418 const openCell = getFirstOpenCellForColumn(colIndex);
419
420 if (!openCell) return;
421
422 openCell.classList.add(greenIsNext ? "green" : "red");
423 checkStatusOfGame(openCell);
424
425 greenIsNext = !greenIsNext;
426 clearColorFromTop(colIndex);
427
428 if (gameIsLive) {
429 const topCell = topCells[colIndex];
430 topCell.classList.add(greenIsNext ? "green" : "red");
431 playerTurn.textContent = `${
432 greenIsNext ? firstPlayer : secondPlayer
433 }'s turn`;
434 }
435};
436
437for (const row of rows) {
438 for (const cell of row) {

Callers

nothing calls this directly

Calls 4

getCellLocationFunction · 0.85
checkStatusOfGameFunction · 0.85
clearColorFromTopFunction · 0.85

Tested by

no test coverage detected