My function createBomb()
is not working because none of the elements are turning into bombs.
I've tried finding the error.
HTML:
<div class = "grid-square" onclick = "check(1,8)" id = "18">?</div>
Javascript:
function createBomb() {
bombNum = Math.floor(Math.random() * 80) + 1;
if (!document.getElementById(bombNum).classList.contains("bomb")) {
document.getElementById(bombNum).classList.add("bomb");
} else {
createBomb();
}
}
createBomb();
I expect the function createBomb()
to make a random div
a bomb.