script.js:65 Uncaught RangeError: Maximum call stack size exceeded

I have tested the code several times but I cannot solve this problem. Here is the whole script I have tested the code several times but I cannot solve this problem. Here is the whole script I have tested the code several times but I cannot solve this problem. Here is the whole script

// Constantes

const container = document.querySelector('.plateau');

const scoreBoard = document.querySelector('.score');

const btnStart = document.querySelector('.btnStart');


// Variables

let derniereCachette = false;

let gameOver = false;

let score = 0;

btnStart.addEventListener('click',startGame);

function startGame(){
    btnStart.getElementsByClassName.display = 'none';
    creationPlateau();
    startZombies();
    score = 0;
    scoreBoard.innerHTML = score;
    scoring();


}

//Fonction pour faire apparaitre les zombies aléatoirement

function startZombies(){

    let cachette = randomUp();

    let temp = Math.floor(Math.random() *3) + 1;

    let tempClass = temp > 1 ? 'up' : 'up2';

    cachette.classList.add(tempClass);

    //calcul du tps d'apparition:
    const time = Math.round(Math.random()* (1500 - 250) +250);

    setTimeout(function(){

        cachette.classList.remove(tempClass);

        if(!gameOver) startZombies();
        
    },time);

}


function randomUp(){

    //On crée une variable pour aller chercher ttes les div qui ont la class = "cachette"

    const cachettes = document.querySelectorAll('.cachette');

    //constante qui va générer un chiffre aléatoire parmi les 9 occurences

    const idx = Math.floor(Math.random() * cachettes.length);

    if(cachettes[idx].zombieId === derniereCachette){
         console.log;

        //on relance la génération de l'index

        return randomUp();
    }

    //ON STOCKE le résultat dans la variable derniereCachette

    derniereCachette = cachettes[idx].zombieId;

    //ON RETOURNE à la valeur obtenue

    return cachettes[idx];
} 



function creationPlateau(){
    let cachetteCrees = 9;

    container.innerHTML = ' ';

    //Création d'une boucle pour la création des div qui représentent les cachettes (pas plus de 9)


    for(let x = 0; x< cachetteCrees; x++){

        //console.log('apparitions');

        //Créer les div

        let div = document.createElement('div');

        //On ajoute une classe à chaque div nouvellement crées

        div.setAttribute('class', 'cachette');

        div.zombieID = x;

        //On crée dynamiquement uen div avec une classe et un évenement (tie) pour les zombies, Lola.

        //Zombies

        let zombie = document.createElement('div');
        zombie.setAttribute('class','zombie');
        zombie.onclick = tir;
        div.appendChild(zombie);

        //Lola

        let lola = document.createElement('div');
        lola.setAttribute('class','lola');
        lola.onclick = tir2;
        div.appendChild(lola);

        // Mur

        let mur = document.createElement('div');
        mur.setAttribute('class','mur');
        div.appendChild(mur);

        //On rattache nos div (9) à la  div plateau

        container.appendChild(div);   
     


    }
}

function scoring(){
    scoreBoard.innerHTML ="Score: " + score;

    let message = score >=10 ? "C'est gagné !" : "Vous avez perdu, voulez vous refaire une partie ?";

    if(score >= 10 || score <0){
        gameOver = true;
        btnStart.getElementsByClassName.display = 'block';

        confirm(message);
        document.location.href = "index.html";
    }
}

function tir(e){

    
score++;
this.parentNode.classList.remove('up');
scoring();

}


function tir2(){

    
score = score-5;
this.parentNode.classList.remove('up2');
scoring();

}

I have tested the code several times but I cannot solve this problem. Here is the whole script I have tested the code several times but I cannot solve this problem. Here is the whole script I have tested the code several times but I cannot solve this problem. Here is the whole script



from Recent Questions - Stack Overflow https://ift.tt/3nPcVag
https://ift.tt/eA8V8J

Comments

Popular posts from this blog

Today Walkin 14th-Sept

Hibernate Search - Elasticsearch with JSON manipulation

Spring Elasticsearch Operations