jeudi 30 septembre 2021

Subtract an image that is representing a life in a game

Im try to code a mini game. The game has two boxes you can click on. The boxes are assigned a random number between 1 and 2.

When the game starts, you have 5 lives. These lives are represented as 5 pictures of a small human.

When the player gets 3,5 and 7 correct points you get a extra life. Which i have achieved.

Now im trying to subtract a life everytime the player clicks on the wrong box.

function setRandomNumber(){ randomNumber = Math.floor( Math.random() * 2 + 1);

        if( randomNumber === 1){

            numberOfRightAnswersSpan.innerHTML = `${++correctNumber}`;
           
            outputDiv.innerHTML = `Det er riktig svar.`;

            if( correctNumber === 3 || correctNumber === 5 || correctNumber === 7){
                numberOfLivesDiv.innerHTML += `<img src="images/person1.jpg"/>`

            }
            }
            else{

            numberOfWrongAnswersSpan.innerHTML = `${++wrongNumber}`;
            outputDiv.innerHTML = `Det er feil svar.`;
            
        }
        
    }

Aucun commentaire:

Enregistrer un commentaire