jeudi 30 septembre 2021

JavaScript - increment with +1 every time random number === 1 from Math.random

I want my encounter to increment every encounter by 1 or 2 it only add the first encounter at 1 or 2, why?

        function setAnswerCorrect() { // Points counter, add hp === 3p,5p,7p
            addPoint = 0;        // scope addPoint
            addPoint++
            minPoint = 0;       // scope minPoint
            minPoint++
            if (randomNumber === 1) { // If num 1

                for (var i = 0; i < randomNumber; i++) { // for num 1 ++
                }
                answerCorrect.innerHTML = `<p>Correct counter: ${addPoint}</p>`

            } else if (randomNumber === 2) {  // else if num 2 then ++

                for (var i = 0; i < randomNumber; i++) {
                }
                answerWrong.innerHTML = `<p>Wrong counter: ${minPoint}</p>`;
            }
        };
        function setRandomNumber() {
            randomNumber = Math.floor(Math.random() * 2 + 1);
            console.log(randomNumber);
        } setRandomNumber();

Aucun commentaire:

Enregistrer un commentaire