Как заставить функцию getHole работать
Пытаюсь сделать игру "Убей крота". Код получился следующий, но не работает((( Помогите, пожалуйста, нубу найти исправить ошибки.
(() => {
let playing = true,
activeHole = 1;
const stop = () => playing = true,
getHole = index => document.getElementById(`hole${index}`),
deactivateHole = index =>
getHole( index ).className = 'hole',
activateHole = index =>
getHole( index ).className = 'hole hole_has-mole',
next = () => setTimeout(() => {
if ( !playing ) {
return;
}
deactivateHole( activeHole );
activeHole = Math.floor( 1 + Math.random() * 9 );
activateHole( activeHole );
next();
}, 800 );
next();
})();
let dead = document.getElementById("dead");
let lost = document.getElementById("lost");
for (let index = 1; index <= 9; index++) {
function getHole (index) {
let holeClick = document.getElementById(`hole${index}`);
return holeClick;
}
let hole = getHole (index);
hole.onclick = function() {
if (hole.className.includes("hole_has-mole") === true) {
dead++;
} else {
lost++;
}
if (dead.textContent === 10) {
alert ("Вы победили!");
dead = 0;
lost = 0;
} else if (lost.textContent === 5) {
alert ("Вы проиграли");
dead = 0;
lost = 0;
}
}
}
Код:
<!doctype html>Код:
.hole-game { |
katjushkabow,
dead.innerHTML++;
} else {
lost.innerHTML++;
и ниже тоже добавить innerHTML. |
| Часовой пояс GMT +3, время: 07:47. |