Загрузка данных


<!DOCTYPE html>
<html lang="ru">
<head>
    <meta charset="UTF-8">
    <title>Whack-a-Mole</title>
    <link rel="stylesheet" href="css/style.css">
</head>
<body>
    <h1>Whack-a-Mole</h1>
    <p>Очки: <span id="score">0</span></p>
    <p>Время: <span id="time">30</span></p>
    <button id="startBtn">Начать игру</button>

    <div class="grid">
        <div class="hole"></div>
        <div class="hole"></div>
        <div class="hole"></div>
        <div class="hole"></div>
        <div class="hole"></div>
        <div class="hole"></div>
        <div class="hole"></div>
        <div class="hole"></div>
        <div class="hole"></div>
    </div>

    <script type="module" src="js/main.js"></script>
</body>
</html>

export function randomHole(holes) {
    // Сначала убираем класс крота у всех лунок, чтобы они не дублировались
    holes.forEach(hole => {
        hole.classList.remove('mole');
    });

    // Генерируем случайный индекс от 0 до 8
    const index = Math.floor(Math.random() * holes.length);
    const hole = holes[index];

    // Добавляем класс крота выбранной лунке
    hole.classList.add('mole');
}