작성
·
236
0
function onLeftClick(e) {
const target = e.target;
const rowIndex = target.parentNode.rowIndex;
const cellIndex = target.cellIndex;
const clikedCellData = tableData[rowIndex][cellIndex];
console.log(clikedCellData);
if (clikedCellData === CODE.FLAG || clikedCellData === CODE.QUESTION) {
console.log('click')
return;
}
if (clikedCellData === CODE.FLAG_MINE || clikedCellData === CODE.QUESTION_MINE || clikedCellData === CODE.MINE) {
alert('펑!');
return;
}
if (clikedCellData === CODE.NORMAL) {
const mineCount = countMine(rowIndex, cellIndex);
target.textContent = mineCount || '';
target.className = 'opened';
tableData[rowIndex][cellIndex] = mineCount;
}
}
순서도대로 작성해봤는데 강좌 코드랑 if문 순서가 다릅니다. 제대로 동작은 하는거같아요! 어떤게 더 좋은 방법인가요? 더 좋은 if문 작성 팁이 따로있을까요?
답변 1
0